from header_common import *
from header_operations import *
from header_parties import *
from header_items import *
from header_skills import *
from header_triggers import *
from header_troops import *
from header_music import *

from module_constants import *

####################################################################################################################
# Simple triggers are the alternative to old style triggers. They do not preserve state, and thus simpler to maintain.
#
#  Each simple trigger contains the following fields:
# 1) Check interval: How frequently this trigger will be checked
# 2) Operation block: This must be a valid operation block. See header_operations.py for reference. 
####################################################################################################################

simple_triggers = [

(ti_on_party_encounter,
[

]),

(ti_simulate_battle,
[

]),

(1.000000,
[
    (try_begin),
        (eq, "$training_ground_position_changed", 0),
        (assign, "$training_ground_position_changed", 1),
        (set_fixed_point_multiplier, 100),
        (position_set_x, pos0, 7050),
        (position_set_y, pos0, 7200),
        (party_set_position, "p_training_ground_3", pos0),
    (try_end),
    (gt, "$auto_besiege_town", 0),
    (gt, "$g_player_besiege_town", 0),
    (ge, "$g_siege_method", 1),
    (store_current_hours, ":var_0"),
    (eq, "$g_siege_force_wait", 0),
    (ge, ":var_0", "$g_siege_method_finish_hours"),
    (neg|is_currently_night),
    (rest_for_hours, 0, 0, 0),

]),

(0.000000,
[
    (call_script, "script_detect_load_restore_custom_troops"),

]),

(0.000000,
[
    (try_begin),
        (gt, "$g_last_rest_center", 0),
        (party_get_battle_opponent, ":var_0", "$g_last_rest_center"),
        (gt, ":var_0", 0),
        (store_faction_of_party, ":var_1", "$g_last_rest_center"),
        (store_relation, ":var_2", ":var_1", "fac_player_supporters_faction"),
        (store_faction_of_party, ":var_3", ":var_0"),
        (store_relation, ":var_4", ":var_3", "fac_player_supporters_faction"),
        (ge, ":var_2", 0),
        (neg|ge, ":var_4", 0),
        (start_encounter, "$g_last_rest_center"),
        (rest_for_hours, 0, 0, 0),
    (else_try),
        (store_current_hours, ":var_5"),
        (assign, ":var_6", 0),
        (try_begin),
            (neg|eq, "$g_check_autos_at_hour", 0),
            (ge, ":var_5", "$g_check_autos_at_hour"),
            (assign, ":var_6", 1),
            (assign, "$g_check_autos_at_hour", 0),
        (try_end),
        (this_or_next|eq, ":var_6", 1),
        (map_free),
        (try_begin),
            (ge, "$auto_menu", 1),
            (jump_to_menu, "$auto_menu"),
            (assign, "$auto_menu", -1),
        (else_try),
            (ge, "$auto_enter_town", 1),
            (start_encounter, "$auto_enter_town"),
        (else_try),
            (ge, "$auto_besiege_town", 1),
            (start_encounter, "$auto_besiege_town"),
        (else_try),
            (ge, "$g_camp_mode", 1),
            (assign, "$g_camp_mode", 0),
            (assign, "$g_infinite_camping", 0),
            (assign, "$g_player_icon_state", 0),
            (rest_for_hours, 0, 0, 0),
            (display_message, "@Breaking camp..."),
        (try_end),
    (try_end),

]),

(0.000000,
[
    (troop_slot_ge, "trp_notification_menu_types", slot_troop_relations_begin, 1),
    (troop_get_slot, ":var_0", "trp_notification_menu_types", slot_troop_relations_begin),
    (troop_get_slot, "$g_notification_menu_var1", "trp_notification_menu_var1", slot_troop_relations_begin),
    (troop_get_slot, "$g_notification_menu_var2", "trp_notification_menu_var2", slot_troop_relations_begin),
    (jump_to_menu, ":var_0"),
    (assign, ":var_1", 2),
    (try_for_range, ":var_2", 1, ":var_1"),
        (try_begin),
            (troop_slot_ge, "trp_notification_menu_types", ":var_2", 1),
            (val_add, ":var_1", 1),
        (try_end),
        (store_sub, ":var_3", ":var_2", 1),
        (troop_get_slot, ":var_4", "trp_notification_menu_types", ":var_2"),
        (troop_set_slot, "trp_notification_menu_types", ":var_3", ":var_4"),
        (troop_get_slot, ":var_4", "trp_notification_menu_var1", ":var_2"),
        (troop_set_slot, "trp_notification_menu_var1", ":var_3", ":var_4"),
        (troop_get_slot, ":var_4", "trp_notification_menu_var2", ":var_2"),
        (troop_set_slot, "trp_notification_menu_var2", ":var_3", ":var_4"),
    (try_end),

]),

(1.000000,
[
    (map_free),
    (call_script, "script_music_set_situation_with_culture", 65536),

]),

(0.000000,
[
    (try_begin),
        (eq, "$caravan_escort_state", 1),
        (party_is_active, "$caravan_escort_party_id"),
        (store_distance_to_party_from_party, ":var_0", "$caravan_escort_destination_town", "$caravan_escort_party_id"),
        (neg|ge, ":var_0", 2),
        (store_distance_to_party_from_party, ":var_1", "p_main_party", "$caravan_escort_party_id"),
        (neg|ge, ":var_1", 5),
        (assign, "$talk_context", 2),
        (assign, "$g_encountered_party", "$caravan_escort_party_id"),
        (party_stack_get_troop_id, ":var_2", "$caravan_escort_party_id", 0),
        (party_stack_get_troop_dna, ":var_3", "$caravan_escort_party_id", 0),
        (start_map_conversation, ":var_2", ":var_3"),
    (try_end),
    (try_begin),
        (gt, "$g_reset_mission_participation", 1),
        (try_for_range, ":var_4", "trp_npc_adonja", "trp_heroes_end"),
            (troop_set_slot, ":var_4", slot_troop_mission_participation, 0),
        (try_end),
    (try_end),

]),

(24.000000,
[
    (try_for_range, ":var_0", "fac_kingdom_1", "fac_kingdoms_end"),
        (faction_get_slot, ":var_1", ":var_0", slot_faction_morale_of_player_troops),
        (store_sub, ":var_2", 140, "$player_right_to_rule"),
        (val_div, ":var_2", 14),
        (val_max, ":var_2", 1),
        (store_div, ":var_3", ":var_1", ":var_2"),
        (val_sub, ":var_1", ":var_3"),
        (faction_set_slot, ":var_0", slot_faction_morale_of_player_troops, ":var_1"),
    (try_end),
    (assign, ":var_4", -1),
    (try_for_range, ":var_5", "trp_npc_adonja", "trp_kingdom_1_lord"),
        (troop_slot_eq, ":var_5", slot_troop_mission_object, 9),
        (assign, ":var_4", ":var_5"),
    (try_end),
    (neg|eq, ":var_4", -1),
    (store_skill_level, ":var_6", skl_trainer, ":var_4"),
    (val_mul, ":var_6", 3),
    (assign, ":var_7", 1000),
    (assign, ":var_8", 960),
    (assign, ":var_9", 970),
    (try_for_range, ":var_10", 0, 2),
        (store_attribute_level, ":var_11", ":var_4", ":var_10"),
        (store_attribute_level, ":var_12", "trp_player_knight", ":var_10"),
        (store_attribute_level, ":var_13", "trp_player_sergeant", ":var_10"),
        (try_begin),
            (gt, ":var_11", ":var_12"),
            (store_sub, ":var_14", ":var_11", ":var_12"),
            (val_sub, ":var_14", 5),
            (val_mul, ":var_14", 2),
            (store_random_in_range, ":var_15", 0, ":var_7"),
            (val_add, ":var_15", ":var_6"),
            (val_add, ":var_15", ":var_14"),
            (ge, ":var_15", ":var_8"),
            (troop_raise_attribute, "trp_player_knight", ":var_10", 1),
        (try_end),
        (try_begin),
            (gt, ":var_11", ":var_13"),
            (store_sub, ":var_16", ":var_12", 2),
            (gt, ":var_16", ":var_13"),
            (store_sub, ":var_14", ":var_11", ":var_13"),
            (val_sub, ":var_14", 5),
            (val_mul, ":var_14", 2),
            (store_random_in_range, ":var_15", 0, ":var_7"),
            (val_add, ":var_15", ":var_6"),
            (val_add, ":var_15", ":var_14"),
            (ge, ":var_15", ":var_9"),
            (troop_raise_attribute, "trp_player_sergeant", ":var_10", 1),
        (try_end),
    (try_end),
    (try_for_range, ":var_17", 0, 42),
        (store_skill_level, ":var_11", ":var_17", ":var_4"),
        (store_skill_level, ":var_12", ":var_17", "trp_player_knight"),
        (store_skill_level, ":var_13", ":var_17", "trp_player_sergeant"),
        (try_begin),
            (gt, ":var_11", ":var_12"),
            (store_sub, ":var_14", ":var_11", ":var_12"),
            (val_sub, ":var_14", 3),
            (val_mul, ":var_14", 5),
            (store_random_in_range, ":var_15", 0, ":var_7"),
            (val_add, ":var_15", ":var_6"),
            (val_add, ":var_15", ":var_14"),
            (ge, ":var_15", ":var_8"),
            (troop_raise_skill, "trp_player_knight", ":var_17", 1),
        (try_end),
        (try_begin),
            (gt, ":var_11", ":var_13"),
            (gt, ":var_12", ":var_13"),
            (store_sub, ":var_14", ":var_11", ":var_13"),
            (val_sub, ":var_14", 3),
            (val_mul, ":var_14", 5),
            (store_random_in_range, ":var_15", 0, ":var_7"),
            (val_add, ":var_15", ":var_6"),
            (val_add, ":var_15", ":var_14"),
            (ge, ":var_15", ":var_9"),
            (troop_raise_skill, "trp_player_sergeant", ":var_17", 1),
        (try_end),
    (try_end),
    (try_for_range, ":var_18", 0, 6),
        (store_proficiency_level, ":var_11", ":var_4", ":var_18"),
        (store_proficiency_level, ":var_12", "trp_player_knight", ":var_18"),
        (store_proficiency_level, ":var_13", "trp_player_sergeant", ":var_18"),
        (try_begin),
            (gt, ":var_11", ":var_12"),
            (store_sub, ":var_14", ":var_11", ":var_12"),
            (val_div, ":var_14", 20),
            (val_sub, ":var_14", 5),
            (val_mul, ":var_14", 5),
            (store_random_in_range, ":var_15", 0, ":var_7"),
            (val_add, ":var_15", ":var_6"),
            (val_add, ":var_15", ":var_14"),
            (ge, ":var_15", ":var_8"),
            (troop_raise_proficiency_linear, "trp_player_knight", ":var_18", 10),
        (try_end),
        (try_begin),
            (gt, ":var_11", ":var_13"),
            (store_sub, ":var_16", ":var_12", 30),
            (gt, ":var_16", ":var_13"),
            (store_sub, ":var_14", ":var_11", ":var_13"),
            (val_div, ":var_14", 20),
            (val_sub, ":var_14", 5),
            (val_mul, ":var_14", 5),
            (store_random_in_range, ":var_15", 0, ":var_7"),
            (val_add, ":var_15", ":var_6"),
            (val_add, ":var_15", ":var_14"),
            (ge, ":var_15", ":var_9"),
            (troop_raise_proficiency_linear, "trp_player_sergeant", ":var_18", 10),
        (try_end),
    (try_end),
    (call_script, "script_copy_complete_troop", "trp_player_knight", "trp_player_knight_save", 0),
    (call_script, "script_copy_complete_troop", "trp_player_sergeant", "trp_player_sergeant_save", 0),
    (try_for_range, ":var_19", 0, 2),
        (try_begin),
            (eq, ":var_19", 0),
            (assign, ":var_20", "trp_player_knight"),
            (assign, ":var_21", "trp_dragon_knight"),
            (assign, ":var_22", "trp_zombie"),
        (else_try),
            (assign, ":var_20", "trp_player_sergeant"),
            (assign, ":var_21", "trp_dragon_drake"),
            (store_sub, ":var_22", "trp_zombie", "trp_dragon_knight"),
            (val_add, ":var_22", "trp_dragon_drake"),
        (try_end),
        (assign, ":var_23", 0),
        (assign, ":var_24", 0),
        (assign, ":var_25", 0),
        (assign, ":var_26", 0),
        (try_for_range, ":var_27", ":var_21", ":var_22"),
            (neg|eq, ":var_27", ":var_20"),
            (troop_get_slot, ":var_28", ":var_27", 169),
            (val_add, ":var_23", ":var_28"),
            (troop_get_slot, ":var_28", ":var_27", 170),
            (val_add, ":var_24", ":var_28"),
            (troop_get_slot, ":var_28", ":var_27", 171),
            (val_add, ":var_25", ":var_28"),
            (try_for_range, ":var_18", 0, 6),
                (store_proficiency_level, ":var_28", ":var_27", ":var_18"),
                (val_add, ":var_26", ":var_28"),
            (try_end),
        (try_end),
        (store_sub, ":var_29", "trp_zombie", "trp_dragon_knight"),
        (val_sub, ":var_29", 1),
        (val_div, ":var_23", ":var_29"),
        (val_div, ":var_24", ":var_29"),
        (val_div, ":var_25", ":var_29"),
        (val_div, ":var_26", 6),
        (val_div, ":var_26", ":var_29"),
        (assign, ":var_30", 0),
        (try_for_range, ":var_18", 0, 6),
            (store_proficiency_level, ":var_28", ":var_20", ":var_18"),
            (val_add, ":var_30", ":var_28"),
        (try_end),
        (val_div, ":var_30", 6),
        (store_mul, ":var_31", ":var_30", 100),
        (val_div, ":var_31", ":var_26"),
        (store_mul, ":var_32", ":var_23", ":var_31"),
        (val_div, ":var_32", 100),
        (troop_set_slot, ":var_20", 169, ":var_32"),
        (store_mul, ":var_32", ":var_24", ":var_31"),
        (val_div, ":var_32", 100),
        (troop_set_slot, ":var_20", 170, ":var_32"),
        (store_mul, ":var_32", ":var_25", ":var_31"),
        (val_div, ":var_32", 100),
        (troop_set_slot, ":var_20", 171, ":var_32"),
    (try_end),

]),

(4.000000,
[
    (try_for_range, ":var_0", "trp_knight_1_1_wife", "trp_heroes_end"),
        (neg|troop_slot_ge, ":var_0", slot_troop_prisoner_of_party, 0),
        (call_script, "script_get_kingdom_lady_social_determinants", ":var_0"),
        (assign, ":var_1", reg1),
        (troop_set_slot, ":var_0", slot_troop_cur_center, ":var_1"),
    (try_end),

]),

(2.000000,
[
    (eq, "$cheat_mode", 1),
    (assign, ":var_0", 0),
    (try_for_parties, ":var_1"),
        (gt, ":var_1", "p_spawn_points_end"),
        (party_stack_get_troop_id, ":var_2", ":var_1", 0),
        (is_between, ":var_2", "trp_npc_adonja", "trp_knight_1_1_wife"),
        (troop_get_slot, ":var_3", ":var_2", slot_troop_leaded_party),
        (neg|eq, ":var_1", ":var_3"),
        (assign, reg4, ":var_1"),
        (assign, reg5, ":var_3"),
        (str_store_troop_name, s3, ":var_2"),
        (display_message, "@{!}{s3} commander of party #{reg4} which is not his troop leaded party {reg5}"),
        (str_store_string, s65, "str_party_with_commander_mismatch__check_log_for_details_"),
        (try_begin),
            (eq, ":var_0", 0),
            (call_script, "script_add_notification_menu", "mnu_debug_alert_from_s65", 0, 0),
            (assign, ":var_0", 1),
        (try_end),
    (try_end),

]),

(24.000000,
[
    (try_begin),
        (neg|check_quest_active, "qst_visit_lady"),
        (neg|troop_slot_ge, "trp_player", slot_troop_prisoner_of_party, 1),
        (neg|troop_slot_ge, "trp_player", slot_troop_spouse, "trp_npc_adonja"),
        (assign, ":var_0", -1),
        (assign, ":var_1", 120),
        (try_for_range, ":var_2", "trp_knight_1_1_wife", "trp_heroes_end"),
            (troop_slot_ge, ":var_2", slot_troop_met, 2),
            (neg|troop_slot_eq, ":var_2", slot_troop_met, 4),
            (troop_slot_eq, ":var_2", slot_troop_love_interest_3, 0),
            (troop_slot_eq, ":var_2", slot_troop_spouse, -1),
            (troop_get_slot, ":var_3", ":var_2", slot_troop_cur_center),
            (is_between, ":var_3", "p_town_1", "p_village_1"),
            (call_script, "script_troop_get_relation_with_troop", "trp_player", ":var_2"),
            (gt, reg0, 1),
            (store_current_hours, ":var_4"),
            (troop_get_slot, ":var_5", ":var_2", slot_troop_last_talk_time),
            (val_sub, ":var_4", ":var_5"),
            (gt, ":var_4", ":var_1"),
            (assign, ":var_1", ":var_4"),
            (assign, ":var_0", ":var_2"),
            (assign, ":var_6", ":var_3"),
        (try_end),
        (try_begin),
            (gt, ":var_0", 0),
            (call_script, "script_add_notification_menu", "mnu_notification_lady_requests_visit", ":var_0", ":var_6"),
        (try_end),
    (try_end),

]),

(1.000000,
[
    (ge, "$g_player_raiding_village", 1),
    (try_begin),
        (neg|eq, "$g_player_is_captive", 0),
        (assign, "$g_player_raiding_village", 0),
    (else_try),
        (map_free),
        (assign, "$g_player_raiding_village", 0),
    (else_try),
        (this_or_next|party_slot_eq, "$g_player_raiding_village", slot_village_state, 2),
        (party_slot_eq, "$g_player_raiding_village", slot_village_state, 4),
        (start_encounter, "$g_player_raiding_village"),
        (rest_for_hours, 0),
        (assign, "$g_player_raiding_village", 0),
        (assign, "$g_player_raid_complete", 1),
    (else_try),
        (party_slot_eq, "$g_player_raiding_village", slot_village_state, 1),
        (rest_for_hours, 3, 5, 1),
    (else_try),
        (rest_for_hours, 0, 0, 0),
        (assign, "$g_player_raiding_village", 0),
        (assign, "$g_player_raid_complete", 0),
    (try_end),

]),

(168.000000,
[
    (call_script, "script_spawn_friendlies"),
    (call_script, "script_spawn_signature", 0),
    (call_script, "script_spawn_renegade"),
    (call_script, "script_spawn_deserters"),
    (call_script, "script_spawn_signature_patrols"),
    (call_script, "script_generate_noble_recruits"),
    (store_relation, ":var_0", "fac_player_faction", "fac_robber_knights"),
    (try_begin),
        (gt, ":var_0", 10),
        (set_relation, "fac_player_faction", "fac_robber_knights", 10),
        (set_relation, "fac_player_supporters_faction", "fac_robber_knights", 10),
    (try_end),
    (store_relation, ":var_0", "fac_player_faction", "fac_heretics"),
    (try_begin),
        (gt, ":var_0", -15),
        (set_relation, "fac_player_faction", "fac_heretics", -15),
        (set_relation, "fac_player_supporters_faction", "fac_heretics", -15),
    (try_end),
    (store_relation, ":var_0", "fac_player_faction", "fac_jatu"),
    (try_begin),
        (gt, ":var_0", 2),
        (set_relation, "fac_player_faction", "fac_jatu", 2),
        (set_relation, "fac_player_supporters_faction", "fac_jatu", 2),
    (try_end),
    (store_relation, ":var_0", "fac_player_faction", "fac_snake_cult"),
    (try_begin),
        (gt, ":var_0", -5),
        (set_relation, "fac_player_faction", "fac_snake_cult", -5),
        (set_relation, "fac_player_supporters_faction", "fac_snake_cult", -5),
    (try_end),
    (store_relation, ":var_0", "fac_player_faction", "fac_adventurers"),
    (try_begin),
        (gt, ":var_0", 10),
        (set_relation, "fac_player_faction", "fac_adventurers", 10),
        (set_relation, "fac_player_supporters_faction", "fac_adventurers", 10),
    (try_end),
    (store_relation, ":var_0", "fac_player_faction", "fac_mystmountain"),
    (try_begin),
        (gt, ":var_0", 10),
        (set_relation, "fac_player_faction", "fac_mystmountain", 10),
        (set_relation, "fac_player_supporters_faction", "fac_mystmountain", 10),
    (try_end),
    (store_relation, ":var_0", "fac_player_faction", "fac_dshar_raiders"),
    (try_begin),
        (gt, ":var_0", 10),
        (set_relation, "fac_player_faction", "fac_dshar_raiders", 10),
        (set_relation, "fac_player_supporters_faction", "fac_dshar_raiders", 10),
    (try_end),
    (store_relation, ":var_0", "fac_player_faction", "fac_singalians"),
    (try_begin),
        (gt, ":var_0", 10),
        (set_relation, "fac_player_faction", "fac_singalians", 10),
        (set_relation, "fac_player_supporters_faction", "fac_singalians", 10),
    (try_end),
    (assign, "$g_presentation_lines_to_display_begin", 0),
    (assign, "$g_presentation_lines_to_display_end", 15),
    (assign, "$g_apply_budget_report_to_gold", 1),
    (try_begin),
        (eq, "$g_infinite_camping", 0),
        (start_presentation, "prsnt_budget_report"),
    (try_end),

]),

(24.000000,
[
    (call_script, "script_copy_complete_troop", "trp_player_knight", "trp_player_knight_save", 0),
    (call_script, "script_copy_complete_troop", "trp_player_sergeant", "trp_player_sergeant_save", 0),
    (try_begin),
        (gt, "$g_pop_upgrade_knight_days", 0),
        (val_sub, "$g_pop_upgrade_knight_days", 1),
        (eq, "$g_pop_upgrade_knight_days", 0),
        (troop_set_inventory_slot, "trp_player_knight_save", "$g_pop_upgrade_knight_slot", "$g_pop_upgrade_knight_item"),
        (call_script, "script_copy_complete_troop", "trp_player_knight_save", "trp_player_knight", 1),
        (str_store_item_name_plural, s11, "$g_pop_upgrade_knight_item"),
        (str_store_troop_name_plural, s12, "trp_player_knight"),
        (display_message, "@Your {s12} have acquired the new {s11}!"),
        (play_sound, "snd_bellchant"),
    (try_end),
    (try_begin),
        (gt, "$g_pop_upgrade_squire_days", 0),
        (val_sub, "$g_pop_upgrade_squire_days", 1),
        (eq, "$g_pop_upgrade_squire_days", 0),
        (troop_set_inventory_slot, "trp_player_sergeant_save", "$g_pop_upgrade_squire_slot", "$g_pop_upgrade_squire_item"),
        (call_script, "script_copy_complete_troop", "trp_player_sergeant_save", "trp_player_sergeant", 1),
        (str_store_item_name_plural, s11, "$g_pop_upgrade_squire_item"),
        (str_store_troop_name_plural, s12, "trp_player_sergeant"),
        (display_message, "@Your {s12} have acquired the new {s11}!"),
        (play_sound, "snd_bellchant"),
    (try_end),
    (neg|gt, "$auto_menu", 0),
    (gt, "$players_kingdom", 0),
    (neg|eq, "$players_kingdom", "fac_player_supporters_faction"),
    (eq, "$player_has_homage", 0),
    (troop_get_slot, ":var_0", "trp_player", slot_troop_spouse),
    (assign, ":var_1", 0),
    (try_begin),
        (is_between, ":var_0", "trp_npc_adonja", "trp_knight_1_1_wife"),
        (store_troop_faction, ":var_2", ":var_0"),
        (eq, ":var_2", "$players_kingdom"),
        (assign, ":var_1", 1),
    (try_end),
    (eq, ":var_1", 0),
    (store_current_day, ":var_3"),
    (gt, ":var_3", "$mercenary_service_next_renew_day"),
    (jump_to_menu, "mnu_oath_fulfilled"),

]),

(200.000000,
[
    (val_sub, "$g_player_luck", 1),
    (val_max, "$g_player_luck", 25),

]),

(96.000000,
[
    (store_random_in_range, ":var_0", 0, 100),
    (neg|ge, ":var_0", 50),
    (call_script, "script_get_number_of_hero_centers", "trp_player"),
    (assign, ":var_1", reg0),
    (try_begin),
        (gt, ":var_1", 0),
        (store_random_in_range, ":var_2", 0, ":var_1"),
        (call_script, "script_troop_get_leaded_center_with_index", "trp_player", ":var_2"),
        (assign, ":var_3", reg0),
        (store_random_in_range, ":var_4", 1, 14),
        (party_set_slot, ":var_3", 296, ":var_4"),
        (call_script, "script_add_notification_menu", "mnu_heartbeat_quest", ":var_3", 0),
    (try_end),

]),

(72.000000,
[
    (assign, "$lady_flirtation_location", 0),

]),

(4.000000,
[
    (assign, "$g_time_to_spare", 1),
    (try_begin),
        (troop_slot_ge, "trp_player", slot_troop_spouse, "trp_npc_adonja"),
        (assign, "$g_player_banner_granted", 1),
    (try_end),

]),

(24.000000,
[
    (eq, "$g_player_banner_granted", 1),
    (troop_slot_eq, "trp_player", slot_troop_banner_scene_prop, 0),
    (neg|gt, "$auto_menu", 0),
    (start_presentation, "prsnt_banner_selection"),

]),

(24.000000,
[
    (call_script, "script_get_player_party_morale_values"),
    (assign, ":var_0", reg0),
    (party_get_morale, ":var_1", "p_main_party"),
    (store_sub, ":var_2", ":var_0", ":var_1"),
    (store_div, ":var_3", ":var_2", 5),
    (store_mul, ":var_4", ":var_3", 5),
    (try_begin),
        (neg|eq, ":var_4", ":var_2"),
        (try_begin),
            (gt, ":var_2", 0),
            (val_add, ":var_3", 1),
        (else_try),
            (val_sub, ":var_3", 1),
        (try_end),
    (try_end),
    (val_add, ":var_1", ":var_3"),
    (party_set_morale, "p_main_party", ":var_1"),

]),

(168.000000,
[
    (try_for_range, ":var_0", "p_town_1", "p_village_1"),
        (party_get_num_prisoner_stacks, ":var_1", ":var_0"),
        (store_div, ":var_2", ":var_1", 2),
        (try_for_range_backwards, ":var_3", 0, ":var_1"),
            (party_prisoner_stack_get_troop_id, ":var_4", ":var_0", ":var_3"),
            (neg|troop_is_hero, ":var_4"),
            (party_prisoner_stack_get_size, ":var_5", ":var_0", ":var_3"),
            (store_random_in_range, ":var_6", 0, 40),
            (val_add, ":var_6", ":var_2"),
            (val_min, ":var_6", 100),
            (try_begin),
                (party_slot_eq, ":var_0", 275, 1),
                (val_div, ":var_6", 2),
            (try_end),
            (val_mul, ":var_5", ":var_6"),
            (val_div, ":var_5", 100),
            (try_begin),
                (ge, ":var_6", 20),
                (val_max, ":var_5", 1),
            (try_end),
            (party_remove_prisoners, ":var_0", ":var_4", ":var_5"),
        (try_end),
    (try_end),

]),

(168.000000,
[
    (try_for_range, ":var_0", "trp_npc_adonja", "trp_knight_1_1_wife"),
        (troop_get_slot, ":var_1", ":var_0", slot_troop_player_debt),
        (val_mul, ":var_1", 101),
        (val_div, ":var_1", 100),
        (troop_set_slot, ":var_0", slot_troop_player_debt, ":var_1"),
        (call_script, "script_calculate_hero_weekly_net_income_and_add_to_wealth", ":var_0"),
    (try_end),
    (try_for_range, ":var_2", "p_town_1", "p_village_1"),
        (neg|party_slot_eq, ":var_2", slot_town_lord, "trp_player"),
        (party_slot_ge, ":var_2", slot_town_lord, 1),
        (party_get_slot, ":var_3", ":var_2", slot_town_wealth),
        (party_get_slot, ":var_4", ":var_2", slot_town_prosperity),
        (party_get_slot, ":var_5", ":var_2", 290),
        (val_mul, ":var_5", 5),
        (store_mul, ":var_6", ":var_4", 14),
        (val_add, ":var_6", 1000),
        (val_add, ":var_6", ":var_5"),
        (try_begin),
            (this_or_next|eq, ":var_2", "p_town_1"),
            (this_or_next|eq, ":var_2", "p_town_5"),
            (this_or_next|eq, ":var_2", "p_town_6"),
            (this_or_next|eq, ":var_2", "p_town_8"),
            (eq, ":var_2", "p_town_10"),
            (val_mul, ":var_6", 12),
            (val_div, ":var_6", 10),
        (try_end),
        (val_add, ":var_3", ":var_6"),
        (call_script, "script_calculate_weekly_party_wage", ":var_2"),
        (val_sub, ":var_3", reg0),
        (val_max, ":var_3", 0),
        (party_set_slot, ":var_2", slot_town_wealth, ":var_3"),
    (try_end),

]),

(24.000000,
[
    (try_for_range, ":var_0", "trp_npc_adonja", "trp_knight_1_1_wife"),
        (troop_slot_eq, ":var_0", slot_troop_occupation, 2),
        (troop_get_slot, ":var_1", ":var_0", slot_troop_leaded_party),
        (ge, ":var_1", 1),
        (party_is_active, ":var_1"),
        (party_get_attached_to, ":var_2", ":var_1"),
        (is_between, ":var_2", "p_town_1", "p_salt_mine"),
        (party_slot_eq, ":var_2", slot_center_is_besieged_by, -1),
        (store_faction_of_party, ":var_3", ":var_1"),
        (try_begin),
            (this_or_next|eq, ":var_3", "fac_player_supporters_faction"),
            (eq, ":var_3", "$players_kingdom"),
            (assign, ":var_4", 1),
            (store_random_in_range, ":var_5", 0, 2),
            (val_add, ":var_4", ":var_5"),
        (else_try),
            (game_get_reduce_campaign_ai, ":var_6"),
            (try_begin),
                (eq, ":var_6", 0),
                (assign, ":var_4", 2),
            (else_try),
                (eq, ":var_6", 1),
                (assign, ":var_4", 1),
                (store_random_in_range, ":var_5", 0, 2),
                (val_add, ":var_4", ":var_5"),
            (else_try),
                (eq, ":var_6", 2),
                (assign, ":var_4", 1),
            (try_end),
        (try_end),
        (try_begin),
            (faction_slot_eq, ":var_3", slot_faction_marshall, ":var_0"),
            (val_add, ":var_4", 1),
        (try_end),
        (try_for_range, ":var_7", 0, ":var_4"),
            (call_script, "script_hire_men_to_kingdom_hero_party", ":var_0"),
        (try_end),
    (try_end),
    (try_for_range, ":var_8", "p_town_1", "p_village_1"),
        (neg|party_slot_eq, ":var_8", slot_town_lord, "trp_player"),
        (party_slot_ge, ":var_8", slot_town_lord, 1),
        (party_slot_eq, ":var_8", slot_center_is_besieged_by, -1),
        (store_faction_of_party, ":var_9", ":var_8"),
        (try_begin),
            (this_or_next|eq, ":var_9", "fac_player_supporters_faction"),
            (eq, ":var_9", "$players_kingdom"),
            (assign, ":var_10", 450),
        (else_try),
            (game_get_reduce_campaign_ai, ":var_6"),
            (assign, ":var_10", 450),
            (try_begin),
                (eq, ":var_6", 0),
                (assign, ":var_10", 300),
                (store_random_in_range, ":var_4", 0, 2),
                (val_add, ":var_4", 1),
            (else_try),
                (eq, ":var_6", 1),
                (assign, ":var_10", 450),
                (assign, ":var_4", 1),
            (else_try),
                (eq, ":var_6", 2),
                (assign, ":var_10", 600),
                (store_random_in_range, ":var_4", 0, 2),
            (try_end),
        (try_end),
        (try_for_range, ":var_7", 0, ":var_4"),
            (party_get_slot, ":var_11", ":var_8", slot_town_wealth),
            (assign, ":var_12", ":var_11"),
            (val_div, ":var_12", 2),
            (gt, ":var_12", ":var_10"),
            (call_script, "script_cf_reinforce_party", ":var_8"),
            (val_sub, ":var_11", ":var_10"),
            (party_set_slot, ":var_8", slot_town_wealth, ":var_11"),
        (try_end),
    (try_end),
    (try_for_range, ":var_8", "p_town_1", "p_salt_mine"),
        (neg|is_between, ":var_8", "p_castle_1", "p_village_1"),
        (call_script, "script_get_center_ideal_prosperity", ":var_8"),
        (assign, ":var_13", reg0),
        (party_get_slot, ":var_14", ":var_8", slot_town_prosperity),
        (try_begin),
            (gt, ":var_14", ":var_13"),
            (call_script, "script_change_center_prosperity", ":var_8", -1),
            (val_add, "$newglob_total_prosperity_from_convergence", -1),
        (else_try),
            (neg|ge, ":var_14", ":var_13"),
            (call_script, "script_change_center_prosperity", ":var_8", 1),
            (val_add, "$newglob_total_prosperity_from_convergence", 1),
        (try_end),
    (try_end),

]),

(360.000000,
[

]),

(6.000000,
[
    (store_current_day, ":var_0"),
    (try_begin),
        (neg|eq, ":var_0", "$g_last_half_payment_check_day"),
        (assign, "$g_last_half_payment_check_day", ":var_0"),
        (try_begin),
            (eq, "$g_half_payment_checkpoint", 1),
            (val_add, "$g_cur_week_half_daily_wage_payments", 1),
        (try_end),
        (assign, "$g_half_payment_checkpoint", 1),
    (try_end),
    (assign, ":var_1", 0),
    (try_begin),
        (neg|map_free),
        (ge, "$g_last_rest_center", 0),
        (this_or_next|party_slot_eq, "$g_last_rest_center", 251, 1),
        (is_between, "$g_last_rest_center", "p_town_1", "p_village_1"),
        (assign, ":var_1", 1),
    (try_end),
    (eq, ":var_1", 0),
    (assign, "$g_half_payment_checkpoint", 0),

]),

(24.000000,
[
    (call_script, "script_randomly_start_war_peace_new", 1),
    (try_begin),
        (store_random_in_range, ":var_0", "p_village_1", "p_salt_mine"),
        (store_random_in_range, ":var_1", "p_village_1", "p_salt_mine"),
        (store_faction_of_party, ":var_2", ":var_0"),
        (store_faction_of_party, ":var_3", ":var_1"),
        (neg|eq, ":var_0", ":var_1"),
        (neg|eq, ":var_2", ":var_3"),
        (call_script, "script_diplomacy_faction_get_diplomatic_status_with_faction", ":var_3", ":var_2"),
        (eq, reg0, 0),
        (try_begin),
            (party_slot_eq, ":var_0", slot_center_original_faction, ":var_3"),
            (call_script, "script_add_notification_menu", "mnu_notification_border_incident", ":var_0", -1),
        (else_try),
            (party_slot_eq, ":var_0", slot_center_ex_faction, ":var_3"),
            (call_script, "script_add_notification_menu", "mnu_notification_border_incident", ":var_0", -1),
        (else_try),
            (set_fixed_point_multiplier, 1),
            (store_distance_to_party_from_party, ":var_4", ":var_0", ":var_1"),
            (neg|ge, ":var_4", 25),
            (call_script, "script_add_notification_menu", "mnu_notification_border_incident", ":var_0", ":var_1"),
        (try_end),
    (try_end),
    (try_for_range, ":var_5", "fac_player_supporters_faction", "fac_kingdoms_end"),
        (faction_slot_eq, ":var_5", slot_faction_state, 0),
        (try_for_range, ":var_6", "fac_player_supporters_faction", "fac_kingdoms_end"),
            (neg|eq, ":var_5", ":var_6"),
            (faction_slot_eq, ":var_6", slot_faction_state, 0),
            (store_add, ":var_7", ":var_6", 120),
            (val_sub, ":var_7", "fac_player_supporters_faction"),
            (faction_get_slot, ":var_8", ":var_5", ":var_7"),
            (try_begin),
                (ge, ":var_8", 1),
                (try_begin),
                    (eq, ":var_8", 1),
                    (call_script, "script_update_faction_notes", ":var_5"),
                    (neg|ge, ":var_5", ":var_6"),
                    (call_script, "script_add_notification_menu", "mnu_notification_truce_expired", ":var_5", ":var_6"),
                (try_end),
                (val_sub, ":var_8", 1),
                (faction_set_slot, ":var_5", ":var_7", ":var_8"),
            (try_end),
            (store_add, ":var_9", ":var_6", 130),
            (val_sub, ":var_9", "fac_player_supporters_faction"),
            (faction_get_slot, ":var_10", ":var_5", ":var_9"),
            (try_begin),
                (ge, ":var_10", 1),
                (try_begin),
                    (store_relation, ":var_11", ":var_5", ":var_6"),
                    (neg|ge, ":var_11", 0),
                    (faction_set_slot, ":var_5", ":var_9", 0),
                (else_try),
                    (eq, ":var_10", 1),
                    (call_script, "script_add_notification_menu", "mnu_notification_casus_belli_expired", ":var_5", ":var_6"),
                    (faction_set_slot, ":var_5", ":var_9", 0),
                (else_try),
                    (val_sub, ":var_10", 1),
                    (faction_set_slot, ":var_5", ":var_9", ":var_10"),
                (try_end),
            (try_end),
            (try_begin),
                (store_relation, ":var_11", ":var_5", ":var_6"),
                (neg|ge, ":var_11", 0),
                (store_add, ":var_12", ":var_6", 140),
                (val_sub, ":var_12", "fac_player_supporters_faction"),
                (faction_get_slot, ":var_13", ":var_5", ":var_12"),
                (val_add, ":var_13", 1),
                (faction_set_slot, ":var_5", ":var_12", ":var_13"),
            (try_end),
        (try_end),
        (call_script, "script_update_faction_notes", ":var_5"),
    (try_end),

]),

(48.000000,
[
    (try_for_range, ":var_0", "trp_npc_adonja", "trp_knight_1_1_wife"),
        (troop_slot_eq, ":var_0", slot_troop_occupation, 2),
        (troop_get_slot, ":var_1", ":var_0", slot_troop_leaded_party),
        (gt, ":var_1", "p_salt_mine"),
        (party_is_active, ":var_1"),
        (store_skill_level, ":var_2", skl_trainer, ":var_0"),
        (val_add, ":var_2", 5),
        (store_mul, ":var_3", ":var_2", 1000),
        (assign, ":var_4", 30),
        (try_begin),
            (store_troop_faction, ":var_5", ":var_0"),
            (neg|eq, ":var_5", "$players_kingdom"),
            (game_get_reduce_campaign_ai, ":var_6"),
            (try_begin),
                (eq, ":var_6", 0),
                (assign, ":var_4", 35),
                (val_mul, ":var_3", 3),
                (val_div, ":var_3", 2),
            (else_try),
                (eq, ":var_6", 2),
                (assign, ":var_4", 25),
                (val_div, ":var_3", 2),
            (try_end),
        (try_end),
        (store_random_in_range, ":var_7", 0, 100),
        (neg|gt, ":var_7", ":var_4"),
        (party_upgrade_with_xp, ":var_1", ":var_3"),
    (try_end),
    (try_for_range, ":var_8", "p_town_1", "p_village_1"),
        (party_get_slot, ":var_9", ":var_8", slot_town_lord),
        (try_begin),
            (neg|eq, ":var_9", "trp_player"),
            (assign, ":var_3", 3000),
            (assign, ":var_4", 30),
            (try_begin),
                (assign, ":var_10", -1),
                (try_begin),
                    (ge, ":var_9", 0),
                    (store_troop_faction, ":var_10", ":var_9"),
                (try_end),
                (neg|eq, ":var_10", "$players_kingdom"),
                (game_get_reduce_campaign_ai, ":var_6"),
                (try_begin),
                    (eq, ":var_6", 0),
                    (assign, ":var_4", 35),
                    (val_mul, ":var_3", 3),
                    (val_div, ":var_3", 2),
                (else_try),
                    (eq, ":var_6", 2),
                    (assign, ":var_4", 25),
                    (val_div, ":var_3", 2),
                (try_end),
            (try_end),
            (store_random_in_range, ":var_7", 0, 100),
            (neg|gt, ":var_7", ":var_4"),
            (party_upgrade_with_xp, ":var_8", ":var_3"),
            (call_script, "script_pop_sort_garrison", ":var_8"),
        (else_try),
            (eq, ":var_9", "trp_player"),
            (party_get_slot, ":var_11", ":var_8", 293),
            (store_skill_level, ":var_12", skl_trainer, ":var_11"),
            (party_get_slot, ":var_13", ":var_8", 274),
            (val_clamp, ":var_13", 0, 2),
            (val_add, ":var_13", 1),
            (store_mul, ":var_3", ":var_12", 50),
            (val_add, ":var_3", 250),
            (val_mul, ":var_3", ":var_13"),
            (party_upgrade_with_xp, ":var_8", ":var_3", 0),
        (try_end),
    (try_end),

]),

(24.000000,
[
    (call_script, "script_process_sieges"),

]),

(2.000000,
[
    (call_script, "script_process_village_raids"),

]),

(7.000000,
[
    (call_script, "script_init_ai_calculation"),
    (try_for_range, ":var_0", "trp_npc_adonja", "trp_knight_1_1_wife"),
        (troop_slot_eq, ":var_0", slot_troop_occupation, 2),
        (call_script, "script_calculate_troop_ai", ":var_0"),
    (try_end),

]),

(24.000000,
[

]),

(24.000000,
[
    (try_for_range, ":var_0", "trp_npc_adonja", "trp_knight_1_1_wife"),
        (troop_get_slot, ":var_1", ":var_0", slot_troop_intrigue_impatience),
        (val_sub, ":var_1", 5),
        (val_max, ":var_1", 0),
        (troop_set_slot, ":var_0", slot_troop_intrigue_impatience, ":var_1"),
    (try_end),
    (store_random_in_range, ":var_2", 1, 3),
    (val_min, ":var_2", 2),
    (try_for_range, ":var_3", "trp_npc_adonja", "trp_knight_1_1_wife"),
        (troop_get_slot, ":var_4", ":var_3", slot_troop_days_on_mission),
        (ge, ":var_4", 1),
        (val_sub, ":var_4", ":var_2"),
        (val_max, ":var_4", 0),
        (troop_set_slot, ":var_3", slot_troop_days_on_mission, ":var_4"),
    (try_end),
    (troop_get_slot, ":var_4", "trp_player", slot_troop_days_on_mission),
    (val_sub, ":var_4", ":var_2"),
    (val_max, ":var_4", 0),
    (troop_set_slot, "trp_player", slot_troop_days_on_mission, ":var_4"),

]),

(8.000000,
[
    (call_script, "script_cf_random_political_event"),
    (call_script, "script_cf_random_political_event"),

]),

(0.500000,
[
    (val_add, "$g_lord_long_term_count", 1),
    (try_begin),
        (neg|is_between, "$g_lord_long_term_count", "trp_kingdom_heroes_including_player_begin", "trp_knight_1_1_wife"),
        (assign, "$g_lord_long_term_count", "trp_kingdom_heroes_including_player_begin"),
    (try_end),
    (assign, ":var_0", "$g_lord_long_term_count"),
    (try_begin),
        (eq, ":var_0", "trp_kingdom_heroes_including_player_begin"),
        (assign, ":var_0", "trp_player"),
    (try_end),
    (try_begin),
        (eq, "$cheat_mode", 1),
        (str_store_troop_name, s9, ":var_0"),
        (display_message, "@{!}DEBUG -- Doing political calculations for {s9}"),
    (try_end),
    (try_begin),
        (troop_slot_eq, ":var_0", slot_troop_occupation, 2),
        (neg|eq, ":var_0", "trp_player"),
        (assign, ":var_1", -1),
        (try_for_range, ":var_2", "p_town_1", "p_salt_mine"),
            (party_slot_eq, ":var_2", slot_town_lord, ":var_0"),
            (assign, ":var_1", ":var_2"),
        (try_end),
        (try_begin),
            (eq, ":var_1", -1),
            (store_troop_faction, ":var_3", ":var_0"),
            (faction_get_slot, ":var_4", ":var_3", slot_faction_leader),
            (troop_get_slot, ":var_5", ":var_0", slot_lord_reputation_type),
            (try_begin),
                (neg|eq, ":var_4", ":var_0"),
                (try_begin),
                    (this_or_next|eq, ":var_5", 2),
                    (this_or_next|eq, ":var_5", 3),
                    (this_or_next|eq, ":var_5", 4),
                    (eq, ":var_5", 5),
                    (call_script, "script_troop_change_relation_with_troop", ":var_0", ":var_4", -2),
                    (val_add, "$total_no_fief_changes", -2),
                (else_try),
                    (eq, ":var_5", 1),
                    (call_script, "script_troop_change_relation_with_troop", ":var_0", ":var_4", -1),
                    (val_add, "$total_no_fief_changes", -1),
                (try_end),
            (try_end),
        (try_end),
    (try_end),
    (try_begin),
        (eq, "$g_option_no_defections", 0),
        (this_or_next|troop_slot_eq, ":var_0", slot_troop_occupation, 2),
        (eq, ":var_0", "trp_player"),
        (try_begin),
            (eq, ":var_0", "trp_player"),
            (assign, ":var_6", "$players_kingdom"),
        (else_try),
            (store_troop_faction, ":var_6", ":var_0"),
        (try_end),
        (faction_get_slot, ":var_4", ":var_6", slot_faction_leader),
        (neg|eq, ":var_0", ":var_4"),
        (neg|is_between, ":var_0", "trp_kingdom_1_lord", "trp_knight_1_1"),
        (neg|is_between, ":var_0", "trp_kingdom_1_pretender", "trp_knight_1_1_wife"),
        (call_script, "script_troop_get_relation_with_troop", ":var_0", ":var_4"),
        (neg|gt, reg0, -90),
        (call_script, "script_cf_troop_can_intrigue", ":var_0", 0),
        (store_random_in_range, ":var_7", 0, 2),
        (try_begin),
            (neg|eq, ":var_7", 0),
            (neg|eq, ":var_0", "trp_player"),
            (call_script, "script_lord_find_alternative_faction", ":var_0"),
            (assign, ":var_8", reg0),
            (is_between, ":var_8", "fac_player_supporters_faction", "fac_kingdoms_end"),
            (str_store_troop_name, s36, ":var_0"),
            (str_store_faction_name_link, s2, ":var_8"),
            (str_store_faction_name_link, s3, ":var_6"),
            (call_script, "script_change_troop_faction", ":var_0", ":var_8"),
            (str_store_string_reg, s1, 36),
            (try_begin),
                (ge, "$cheat_mode", 1),
                (str_store_troop_name, s4, ":var_0"),
                (display_message, "@{!}DEBUG - {s4} faction changed in defection"),
            (try_end),
            (troop_get_type, reg4, ":var_0"),
            (str_store_string, s4, "str_lord_defects_ordinary"),
            (str_store_troop_name_link, s7, ":var_0"),
            (str_store_string, s4, "@{s4}, and is now known as {s7}"),
            (display_log_message, "@{!}{s4}", 0x66CCFF),
            (try_begin),
                (eq, "$cheat_mode", 1),
                (this_or_next|eq, ":var_8", "$players_kingdom"),
                (eq, ":var_6", "$players_kingdom"),
                (call_script, "script_add_notification_menu", "mnu_notification_lord_defects", ":var_0", ":var_6"),
            (try_end),
        (else_try),
            (neg|eq, ":var_4", "trp_player"),
            (call_script, "script_indict_lord_for_treason", ":var_0", ":var_6"),
        (try_end),
    (else_try),
        (neg|eq, ":var_0", "trp_player"),
        (store_troop_faction, ":var_6", ":var_0"),
        (faction_slot_ge, ":var_6", slot_faction_political_issue, 1),
        (neg|troop_slot_ge, ":var_0", slot_troop_stance_on_faction_issue, 1),
        (this_or_next|troop_slot_eq, ":var_0", slot_troop_stance_on_faction_issue, -1),
        (neg|eq, "$players_kingdom", ":var_6"),
        (troop_slot_eq, ":var_0", slot_troop_occupation, 2),
        (call_script, "script_npc_decision_checklist_take_stand_on_issue", ":var_0"),
        (troop_set_slot, ":var_0", slot_troop_stance_on_faction_issue, reg0),
    (try_end),
    (try_for_range, ":var_9", "trp_npc_adonja", "trp_knight_1_1_wife"),
        (call_script, "script_troop_get_relation_with_troop", ":var_0", ":var_9"),
        (neg|ge, reg0, 0),
        (assign, ":var_10", reg0),
        (store_sub, ":var_11", 0, ":var_10"),
        (store_random_in_range, ":var_12", 0, 300),
        (neg|ge, ":var_12", ":var_11"),
        (assign, ":var_13", 1),
        (try_begin),
            (neg|eq, ":var_0", "trp_player"),
            (neg|eq, ":var_9", "trp_player"),
            (store_troop_faction, ":var_6", ":var_0"),
            (faction_get_slot, ":var_4", ":var_6", slot_faction_leader),
            (eq, ":var_9", ":var_4"),
            (store_random_in_range, ":var_13", 0, 4),
            (try_for_range, ":var_2", "p_town_1", "p_salt_mine"),
                (party_slot_eq, ":var_2", slot_town_lord, ":var_0"),
                (try_begin),
                    (is_between, ":var_2", "p_town_1", "p_castle_1"),
                    (val_add, ":var_13", 3),
                (else_try),
                    (is_between, ":var_2", "p_castle_1", "p_village_1"),
                    (val_add, ":var_13", 2),
                (else_try),
                    (val_add, ":var_13", 1),
                (try_end),
            (try_end),
            (try_begin),
                (eq, "$cheat_mode", 1),
                (assign, reg0, ":var_13"),
                (str_store_troop_name, s9, ":var_0"),
                (display_message, "@{!}DEBUG -- {s9} has gained {reg0} relation with his liege."),
            (try_end),
        (try_end),
        (call_script, "script_troop_change_relation_with_troop", ":var_0", ":var_9", ":var_13"),
        (val_add, "$total_relation_changes_through_convergence", ":var_13"),
    (try_end),

]),

(2.000000,
[

]),

(1.000000,
[
    (call_script, "script_process_alarms"),
    (call_script, "script_allow_vassals_to_join_indoor_battle"),
    (call_script, "script_process_kingdom_parties_ai"),

]),

(3.000000,
[
    (store_current_hours, ":var_0"),
    (try_for_range, ":var_1", "p_town_1", "p_village_1"),
        (party_get_slot, ":var_2", ":var_1", slot_center_is_besieged_by),
        (gt, ":var_2", 0),
        (party_is_active, ":var_2"),
        (store_faction_of_party, ":var_3", ":var_2"),
        (party_slot_ge, ":var_1", slot_center_is_besieged_by, 1),
        (party_get_slot, ":var_4", ":var_1", slot_center_siege_begin_hours),
        (store_sub, ":var_4", ":var_0", ":var_4"),
        (assign, ":var_5", 0),
        (assign, ":var_6", 0),
        (assign, ":var_7", 0),
        (assign, ":var_8", 0),
        (try_for_range, ":var_9", "trp_npc_adonja", "trp_knight_1_1_wife"),
            (troop_slot_eq, ":var_9", slot_troop_occupation, 2),
            (neg|troop_slot_ge, ":var_9", slot_troop_prisoner_of_party, 0),
            (troop_get_slot, ":var_10", ":var_9", slot_troop_leaded_party),
            (gt, ":var_10", 0),
            (party_is_active, ":var_10"),
            (store_troop_faction, ":var_11", ":var_9"),
            (eq, ":var_11", ":var_3"),
            (assign, ":var_12", 0),
            (try_begin),
                (party_slot_eq, ":var_10", slot_party_ai_state, 1),
                (party_slot_eq, ":var_10", slot_party_ai_object, ":var_1"),
                (assign, ":var_12", 1),
            (else_try),
                (party_slot_eq, ":var_10", slot_party_ai_state, 11),
                (party_get_slot, ":var_13", ":var_10", slot_party_ai_object),
                (gt, ":var_13", 0),
                (party_is_active, ":var_13"),
                (party_slot_eq, ":var_13", slot_party_ai_state, 1),
                (party_slot_eq, ":var_13", slot_party_ai_object, ":var_1"),
                (assign, ":var_12", 1),
            (try_end),
            (eq, ":var_12", 1),
            (party_get_battle_opponent, ":var_14", ":var_10"),
            (this_or_next|neg|ge, ":var_14", 0),
            (eq, ":var_14", ":var_1"),
            (try_begin),
                (faction_slot_eq, ":var_3", slot_faction_marshall, ":var_9"),
                (assign, ":var_8", 1),
            (try_end),
            (call_script, "script_party_calculate_regular_strength", ":var_10"),
            (val_add, ":var_7", reg0),
        (try_end),
        (try_begin),
            (gt, ":var_7", 0),
            (party_collect_attachments_to_party, ":var_1", "p_collective_enemy"),
            (call_script, "script_party_calculate_regular_strength", "p_collective_enemy"),
            (assign, ":var_15", reg0),
            (try_begin),
                (eq, "$auto_enter_town", ":var_1"),
                (eq, "$g_player_is_captive", 0),
                (call_script, "script_party_calculate_regular_strength", "p_main_party"),
                (val_add, ":var_15", reg0),
                (val_mul, ":var_7", 2),
            (try_end),
            (party_get_slot, ":var_16", ":var_1", slot_center_siege_hardness),
            (val_add, ":var_16", 100),
            (val_mul, ":var_15", ":var_16"),
            (val_div, ":var_15", 100),
            (val_max, ":var_15", 1),
            (try_begin),
                (eq, ":var_8", 1),
                (eq, ":var_3", "$players_kingdom"),
                (check_quest_active, "qst_follow_army"),
                (val_mul, ":var_7", 2),
            (try_end),
            (val_mul, ":var_7", 3),
            (val_div, ":var_7", 4),
            (try_begin),
                (party_slot_eq, ":var_1", slot_party_type, 2),
                (val_mul, ":var_15", 13),
                (val_div, ":var_15", 10),
            (else_try),
                (party_slot_eq, ":var_1", slot_party_type, 3),
                (val_mul, ":var_15", 15),
                (val_div, ":var_15", 10),
            (try_end),
            (store_mul, ":var_17", ":var_7", 100),
            (val_div, ":var_17", ":var_15"),
            (store_sub, ":var_18", ":var_17", 250),
            (try_begin),
                (gt, ":var_18", -100),
                (store_div, ":var_19", ":var_4", 2),
                (val_add, ":var_18", ":var_19"),
            (try_end),
            (val_div, ":var_18", 5),
            (val_max, ":var_18", 0),
            (store_sub, ":var_20", 175, ":var_17"),
            (val_max, ":var_20", 0),
            (try_begin),
                (store_random_in_range, ":var_21", 0, 100),
                (neg|ge, ":var_21", ":var_18"),
                (gt, ":var_4", 24),
                (assign, ":var_5", 1),
            (else_try),
                (store_random_in_range, ":var_21", 0, 100),
                (neg|ge, ":var_21", ":var_20"),
                (assign, ":var_6", 1),
            (try_end),
        (else_try),
            (assign, ":var_6", 1),
        (try_end),
        (try_begin),
            (eq, ":var_5", 1),
            (call_script, "script_begin_assault_on_center", ":var_1"),
        (else_try),
            (eq, ":var_6", 1),
            (try_for_range, ":var_9", "trp_npc_adonja", "trp_knight_1_1_wife"),
                (troop_slot_eq, ":var_9", slot_troop_occupation, 2),
                (neg|troop_slot_ge, ":var_9", slot_troop_prisoner_of_party, 0),
                (troop_get_slot, ":var_10", ":var_9", slot_troop_leaded_party),
                (gt, ":var_10", 0),
                (party_is_active, ":var_10"),
                (party_slot_eq, ":var_10", slot_party_ai_state, 1),
                (party_slot_eq, ":var_10", slot_party_ai_object, ":var_1"),
                (party_slot_eq, ":var_10", slot_party_ai_substate, 1),
                (call_script, "script_party_set_ai_state", ":var_10", -1, -1),
                (call_script, "script_party_set_ai_state", ":var_10", 1, ":var_1"),
                (party_set_slot, ":var_1", slot_center_siege_begin_hours, ":var_0"),
            (try_end),
        (try_end),
    (try_end),

]),

(6.000000,
[
    (assign, "$g_recalculate_ais", 1),

]),

(0.000000,
[
    (try_begin),
        (ge, "$cheat_mode", 1),
        (try_for_range, ":var_0", "trp_kingdom_1_lord", "trp_knight_1_1"),
            (store_add, ":var_1", ":var_0", "fac_kingdom_1"),
            (val_sub, ":var_1", "trp_kingdom_1_lord"),
            (store_troop_faction, ":var_2", ":var_0"),
            (neg|eq, ":var_1", ":var_2"),
            (neg|eq, ":var_2", "fac_commoners"),
            (ge, "$cheat_mode", 2),
            (neg|eq, ":var_0", "trp_kingdom_2_lord"),
            (str_store_troop_name, s4, ":var_0"),
            (str_store_faction_name, s5, ":var_2"),
            (str_store_faction_name, s6, ":var_1"),
            (str_store_string, s65, "@{!}DEBUG - {s4} is in {s5}, should be in {s6}, disabling political cheat mode"),
            (rest_for_hours, 0, 0, 0),
            (assign, "$cheat_mode", 1),
            (jump_to_menu, "mnu_debug_alert_from_s65"),
        (try_end),
    (try_end),
    (eq, "$g_recalculate_ais", 1),
    (assign, "$g_recalculate_ais", 0),
    (call_script, "script_recalculate_ais"),

]),

(24.000000,
[
    (try_for_range, ":var_0", "fac_player_supporters_faction", "fac_kingdoms_end"),
        (call_script, "script_faction_recalculate_strength", ":var_0"),
    (try_end),
    (try_for_range, ":var_1", "trp_npc_adonja", "trp_knight_1_1_wife"),
        (store_troop_faction, ":var_2", ":var_1"),
        (neg|faction_slot_eq, ":var_2", slot_faction_ai_state, 0),
        (neg|faction_slot_eq, ":var_2", slot_faction_ai_state, 6),
        (neg|faction_slot_eq, ":var_2", slot_faction_ai_state, 1),
        (troop_get_slot, ":var_3", ":var_1", slot_troop_leaded_party),
        (party_is_active, ":var_3"),
        (val_add, "$total_vassal_days_on_campaign", 1),
        (party_slot_eq, ":var_3", slot_party_ai_state, 11),
        (val_add, "$total_vassal_days_responding_to_campaign", 1),
    (try_end),

]),

(36.000000,
[
    (try_for_range, ":var_0", "trp_npc_adonja", "trp_heroes_end"),
        (troop_set_slot, ":var_0", slot_troop_does_not_give_quest, 0),
    (try_end),
    (try_for_range, ":var_0", "trp_village_1_elder", "trp_merchants_end"),
        (troop_set_slot, ":var_0", slot_troop_does_not_give_quest, 0),
    (try_end),

]),

(24.000000,
[
    (try_for_range, ":var_0", "p_village_1", "p_salt_mine"),
        (call_script, "script_refresh_village_merchant_inventory", ":var_0"),
    (try_end),

]),

(48.000000,
[
    (try_for_range, ":var_0", "p_village_1", "p_salt_mine"),
        (call_script, "script_refresh_village_defenders", ":var_0"),
        (party_set_slot, ":var_0", slot_village_player_can_not_steal_cattle, 0),
    (try_end),

]),

(168.000000,
[
    (try_for_range, ":var_0", "p_town_1", "p_salt_mine"),
        (neg|is_between, ":var_0", "p_castle_1", "p_village_1"),
        (party_get_slot, ":var_1", ":var_0", slot_town_trade_routes_end),
        (party_get_slot, ":var_2", ":var_0", slot_center_head_sheep),
        (party_get_slot, ":var_3", ":var_0", slot_center_acres_pasture),
        (val_max, ":var_3", 1),
        (store_mul, ":var_4", ":var_1", 400),
        (store_mul, ":var_5", ":var_2", 200),
        (val_add, ":var_4", ":var_5"),
        (val_div, ":var_4", ":var_3"),
        (store_random_in_range, ":var_6", 0, 100),
        (try_begin),
            (eq, ":var_6", 0),
            (val_min, ":var_1", 10),
        (else_try),
            (gt, ":var_4", 100),
            (val_mul, ":var_2", 90),
            (val_div, ":var_2", 100),
            (val_mul, ":var_1", 90),
            (val_div, ":var_1", 100),
        (else_try),
            (neg|ge, ":var_4", 30),
            (val_mul, ":var_1", 120),
            (val_div, ":var_1", 100),
            (val_add, ":var_1", 1),
            (val_mul, ":var_2", 120),
            (val_div, ":var_2", 100),
            (val_add, ":var_2", 1),
        (else_try),
            (neg|ge, ":var_4", 60),
            (val_mul, ":var_1", 110),
            (val_div, ":var_1", 100),
            (val_add, ":var_1", 1),
            (val_mul, ":var_2", 110),
            (val_div, ":var_2", 100),
            (val_add, ":var_2", 1),
        (else_try),
            (neg|ge, ":var_4", 100),
            (neg|ge, ":var_6", 50),
            (val_mul, ":var_1", 105),
            (val_div, ":var_1", 100),
            (try_begin),
                (neg|gt, ":var_1", 20),
                (val_add, ":var_1", 1),
            (try_end),
            (val_mul, ":var_2", 105),
            (val_div, ":var_2", 100),
            (try_begin),
                (neg|gt, ":var_2", 20),
                (val_add, ":var_2", 1),
            (try_end),
        (try_end),
        (party_set_slot, ":var_0", slot_town_trade_routes_end, ":var_1"),
        (party_set_slot, ":var_0", slot_center_head_sheep, ":var_2"),
    (try_end),

]),

(720.000000,
[
    (try_for_range, ":var_0", "p_town_1", "p_salt_mine"),
        (party_get_slot, ":var_1", ":var_0", slot_town_lord),
        (neg|eq, ":var_1", "trp_player"),
        (is_between, ":var_1", "trp_npc_adonja", "trp_knight_1_1_wife"),
        (party_get_slot, ":var_2", ":var_0", slot_center_accumulated_rents),
        (party_get_slot, ":var_3", ":var_0", slot_center_accumulated_tariffs),
        (troop_get_slot, ":var_4", ":var_1", slot_troop_wealth),
        (val_add, ":var_4", ":var_2"),
        (val_add, ":var_4", ":var_3"),
        (troop_set_slot, ":var_1", slot_troop_wealth, ":var_4"),
        (party_set_slot, ":var_0", slot_center_accumulated_rents, 0),
        (party_set_slot, ":var_0", slot_center_accumulated_tariffs, 0),
        (try_begin),
            (store_troop_faction, ":var_5", ":var_1"),
            (this_or_next|eq, ":var_5", "fac_player_faction"),
            (eq, ":var_5", "fac_player_supporters_faction"),
            (assign, reg1, ":var_4"),
            (add_troop_note_from_sreg, ":var_1", 1, "str_current_wealth_reg1", 1),
        (else_try),
            (add_troop_note_from_sreg, ":var_1", 1, "str_empty_string", 0),
        (try_end),
    (try_end),

]),

(168.000000,
[
    (try_for_range, ":var_0", "p_town_1", "p_salt_mine"),
        (try_begin),
            (party_slot_ge, ":var_0", slot_town_lord, 0),
            (party_get_slot, ":var_1", ":var_0", slot_center_accumulated_rents),
            (assign, ":var_2", 0),
            (party_get_slot, ":var_3", ":var_0", 290),
            (try_begin),
                (party_slot_eq, ":var_0", slot_party_type, 4),
                (try_begin),
                    (party_slot_eq, ":var_0", slot_village_state, 0),
                    (assign, ":var_2", 600),
                    (val_mul, ":var_3", 4),
                    (val_add, ":var_2", ":var_3"),
                (try_end),
            (else_try),
                (party_slot_eq, ":var_0", slot_party_type, 2),
                (assign, ":var_2", 600),
                (val_mul, ":var_3", 6),
                (val_add, ":var_2", ":var_3"),
            (else_try),
                (party_slot_eq, ":var_0", slot_party_type, 3),
                (assign, ":var_2", 1200),
                (val_mul, ":var_3", 6),
                (val_add, ":var_2", ":var_3"),
            (try_end),
            (party_get_slot, ":var_4", ":var_0", slot_town_prosperity),
            (store_add, ":var_5", 60, ":var_4"),
            (val_mul, ":var_2", ":var_5"),
            (val_div, ":var_2", 360),
            (try_begin),
                (party_slot_eq, ":var_0", slot_town_lord, "trp_player"),
                (val_mul, ":var_2", 3),
                (val_div, ":var_2", 2),
                (game_get_reduce_campaign_ai, ":var_6"),
                (try_begin),
                    (eq, ":var_6", 0),
                    (val_mul, ":var_2", 3),
                    (val_div, ":var_2", 4),
                (else_try),
                    (eq, ":var_6", 1),
                (else_try),
                    (eq, ":var_6", 2),
                    (val_mul, ":var_2", 4),
                    (val_div, ":var_2", 3),
                (try_end),
            (else_try),
                (neg|party_slot_eq, ":var_0", slot_town_lord, "trp_player"),
                (store_current_day, ":var_7"),
                (ge, ":var_7", 400),
                (store_character_level, ":var_8", "trp_player"),
                (store_sub, ":var_9", ":var_8", 30),
                (val_clamp, ":var_9", 0, 21),
                (val_mul, ":var_9", 2),
                (val_add, ":var_9", 100),
                (val_sub, ":var_7", 400),
                (val_div, ":var_7", 6),
                (val_add, ":var_9", ":var_7"),
                (val_mul, ":var_2", ":var_9"),
                (val_div, ":var_2", 100),
            (try_end),
            (val_add, ":var_1", ":var_2"),
            (party_set_slot, ":var_0", slot_center_accumulated_rents, ":var_1"),
        (try_end),
        (try_begin),
            (is_between, ":var_0", "p_village_1", "p_salt_mine"),
            (party_get_slot, ":var_10", ":var_0", slot_village_bound_center),
            (party_slot_ge, ":var_10", slot_town_lord, 0),
            (is_between, ":var_10", "p_castle_1", "p_village_1"),
            (party_get_slot, ":var_1", ":var_10", slot_center_accumulated_rents),
            (val_add, ":var_1", ":var_2"),
            (party_set_slot, ":var_10", slot_center_accumulated_rents, ":var_1"),
        (try_end),
    (try_end),

]),

(32.000000,
[
    (eq, "$players_kingdom", 0),
    (neg|gt, "$g_invite_faction", 0),
    (eq, "$g_player_is_captive", 0),
    (try_begin),
        (store_random_in_range, ":var_0", "fac_kingdom_1", "fac_kingdoms_end"),
        (assign, ":var_1", 999999),
        (try_for_range, ":var_2", "p_town_1", "p_village_1"),
            (store_faction_of_party, ":var_3", ":var_2"),
            (eq, ":var_3", ":var_0"),
            (store_distance_to_party_from_party, ":var_4", "p_main_party", ":var_2"),
            (val_min, ":var_1", ":var_4"),
        (try_end),
        (neg|ge, ":var_1", 30),
        (store_relation, ":var_5", ":var_0", "fac_player_supporters_faction"),
        (faction_get_slot, ":var_6", ":var_0", slot_faction_leader),
        (call_script, "script_troop_get_player_relation", ":var_6"),
        (assign, ":var_7", reg0),
        (call_script, "script_get_number_of_hero_centers", "trp_player"),
        (assign, ":var_8", reg0),
        (eq, "$g_infinite_camping", 0),
        (assign, ":var_9", 0),
        (try_begin),
            (ge, "p_main_party", 0),
            (store_party_size_wo_prisoners, ":var_9", "p_main_party"),
        (try_end),
        (try_begin),
            (eq, ":var_8", 0),
            (troop_get_slot, ":var_10", "trp_player", slot_troop_renown),
            (ge, ":var_10", 160),
            (ge, ":var_5", 0),
            (ge, ":var_7", 0),
            (ge, ":var_9", 45),
            (store_random_in_range, ":var_11", 0, 100),
            (neg|ge, ":var_11", 50),
            (call_script, "script_get_poorest_village_of_faction", ":var_0"),
            (assign, "$g_invite_offered_center", reg0),
            (ge, "$g_invite_offered_center", 0),
            (assign, "$g_invite_faction", ":var_0"),
            (jump_to_menu, "mnu_invite_player_to_faction"),
        (else_try),
            (gt, ":var_8", 0),
            (neg|eq, "$players_oath_renounced_against_kingdom", ":var_0"),
            (ge, ":var_5", -40),
            (ge, ":var_7", -20),
            (ge, ":var_9", 30),
            (store_random_in_range, ":var_11", 0, 100),
            (neg|ge, ":var_11", 20),
            (assign, "$g_invite_faction", ":var_0"),
            (assign, "$g_invite_offered_center", -1),
            (jump_to_menu, "mnu_invite_player_to_faction_without_center"),
        (try_end),
    (try_end),

]),

(168.000000,
[
    (try_for_range, ":var_0", "trp_npc_adonja", "trp_knight_1_1_wife"),
        (store_random_in_range, ":var_1", 0, 9999),
        (troop_set_slot, ":var_0", slot_troop_temp_decision_seed, ":var_1"),
    (try_end),

]),

(0.100000,
[
    (try_for_range, ":var_0", "trp_kingdom_1_lord", "trp_knight_1_1"),
        (troop_get_slot, ":var_1", ":var_0", slot_troop_will_join_prison_break),
        (gt, ":var_1", 0),
        (party_is_active, ":var_1"),
        (party_get_attached_to, ":var_2", ":var_1"),
        (neg|ge, ":var_2", 1),
        (party_get_cur_town, ":var_3", ":var_1"),
        (is_between, ":var_3", "p_town_1", "p_salt_mine"),
        (troop_get_slot, ":var_4", ":var_0", slot_troop_leaded_party),
        (ge, ":var_4", 1),
        (party_is_active, ":var_4"),
        (party_get_attached_to, ":var_2", ":var_4"),
        (eq, ":var_2", ":var_3"),
        (party_attach_to_party, ":var_1", ":var_3"),
        (try_begin),
            (this_or_next|party_slot_eq, ":var_3", slot_party_type, 3),
            (party_slot_eq, ":var_3", slot_party_type, 2),
            (store_faction_of_party, ":var_5", ":var_1"),
            (store_faction_of_party, ":var_6", ":var_3"),
            (eq, ":var_5", ":var_6"),
            (call_script, "script_lord_sell_prisoners", ":var_0", ":var_3"),
            (party_get_num_prisoner_stacks, ":var_7", ":var_1"),
            (gt, ":var_7", 0),
            (assign, "$g_move_heroes", 1),
            (call_script, "script_party_prisoners_add_party_prisoners", ":var_3", ":var_1"),
            (assign, "$g_move_heroes", 1),
            (call_script, "script_party_remove_all_prisoners", ":var_1"),
        (try_end),
    (try_end),
    (try_begin),
        (troop_get_slot, ":var_1", "trp_player", slot_troop_will_join_prison_break),
        (gt, ":var_1", 0),
        (party_is_active, ":var_1"),
        (party_get_attached_to, ":var_2", ":var_1"),
        (neg|ge, ":var_2", 1),
        (party_get_cur_town, ":var_3", ":var_1"),
        (is_between, ":var_3", "p_town_1", "p_village_1"),
        (store_faction_of_party, ":var_8", ":var_3"),
        (try_begin),
            (neg|eq, ":var_8", "fac_player_supporters_faction"),
            (party_set_ai_behavior, ":var_1", 10),
            (party_set_ai_object, ":var_1", "p_main_party"),
            (party_set_flags, ":var_1", 65536, 0),
            (party_set_ai_initiative, ":var_1", 10),
        (try_end),
        (eq, ":var_8", "fac_player_supporters_faction"),
        (party_attach_to_party, ":var_1", ":var_3"),
        (party_get_template_id, ":var_9", ":var_1"),
        (try_begin),
            (neg|eq, ":var_9", "pt_player_merc_singalians"),
            (this_or_next|party_slot_eq, ":var_3", slot_party_type, 3),
            (party_slot_eq, ":var_3", slot_party_type, 2),
            (store_faction_of_party, ":var_5", ":var_1"),
            (store_faction_of_party, ":var_6", ":var_3"),
            (eq, ":var_5", ":var_6"),
            (call_script, "script_lord_sell_prisoners", ":var_0", ":var_3"),
            (party_get_num_prisoner_stacks, ":var_7", ":var_1"),
            (gt, ":var_7", 0),
            (assign, "$g_move_heroes", 1),
            (call_script, "script_party_prisoners_add_party_prisoners", ":var_3", ":var_1"),
            (assign, "$g_move_heroes", 1),
            (call_script, "script_party_remove_all_prisoners", ":var_1"),
        (try_end),
    (try_end),
    (try_for_range, ":var_0", "trp_npc_adonja", "trp_heroes_end"),
        (troop_slot_eq, ":var_0", slot_troop_occupation, 2),
        (troop_get_slot, ":var_4", ":var_0", slot_troop_leaded_party),
        (ge, ":var_4", 1),
        (party_is_active, ":var_4"),
        (party_get_attached_to, ":var_2", ":var_4"),
        (neg|ge, ":var_2", 1),
        (party_get_cur_town, ":var_3", ":var_4"),
        (is_between, ":var_3", "p_town_1", "p_salt_mine"),
        (call_script, "script_get_relation_between_parties", ":var_3", ":var_4"),
        (try_begin),
            (ge, reg0, 0),
            (party_attach_to_party, ":var_4", ":var_3"),
            (try_begin),
                (is_between, ":var_0", "trp_kingdom_1_lord", "trp_knight_1_1"),
                (troop_get_slot, ":var_1", ":var_0", slot_troop_will_join_prison_break),
                (gt, ":var_1", 0),
                (party_is_active, ":var_1"),
                (party_set_ai_behavior, ":var_1", 1),
                (party_set_ai_object, ":var_1", ":var_3"),
            (try_end),
        (else_try),
            (party_set_ai_behavior, ":var_4", 0),
        (try_end),
        (try_begin),
            (this_or_next|party_slot_eq, ":var_3", slot_party_type, 3),
            (party_slot_eq, ":var_3", slot_party_type, 2),
            (store_faction_of_party, ":var_5", ":var_4"),
            (store_faction_of_party, ":var_6", ":var_3"),
            (eq, ":var_5", ":var_6"),
            (call_script, "script_lord_sell_prisoners", ":var_0", ":var_3"),
            (party_get_num_prisoner_stacks, ":var_7", ":var_4"),
            (gt, ":var_7", 0),
            (assign, "$g_move_heroes", 1),
            (call_script, "script_party_prisoners_add_party_prisoners", ":var_3", ":var_4"),
            (assign, "$g_move_heroes", 1),
            (call_script, "script_party_remove_all_prisoners", ":var_4"),
        (try_end),
    (try_end),
    (try_for_parties, ":var_10"),
        (gt, ":var_10", "p_spawn_points_end"),
        (party_get_template_id, ":var_11", ":var_10"),
        (ge, ":var_11", "pt_steppe_bandit_lair"),
        (store_distance_to_party_from_party, ":var_12", "p_main_party", ":var_10"),
        (neg|ge, ":var_12", 3),
        (party_set_flags, ":var_10", 256, 0),
        (party_set_flags, ":var_10", 16384, 1),
    (try_end),

]),

(48.000000,
[
    (call_script, "script_randomly_make_prisoner_heroes_escape_from_party", "p_main_party", 50),
    (try_for_range, ":var_0", "p_town_1", "p_village_1"),
        (assign, ":var_1", 30),
        (try_begin),
            (party_slot_eq, ":var_0", 275, 1),
            (assign, ":var_1", 5),
        (try_end),
        (call_script, "script_randomly_make_prisoner_heroes_escape_from_party", ":var_0", ":var_1"),
    (try_end),

]),

(48.000000,
[
    (try_for_range, ":var_0", "trp_npc_adonja", "trp_knight_1_1_wife"),
        (troop_slot_eq, ":var_0", slot_troop_occupation, 2),
        (neg|troop_slot_ge, ":var_0", slot_troop_prisoner_of_party, 0),
        (neg|troop_slot_ge, ":var_0", slot_troop_leaded_party, 1),
        (store_troop_faction, ":var_1", ":var_0"),
        (try_begin),
            (eq, ":var_1", "fac_outlaws"),
        (else_try),
            (try_begin),
                (eq, "$cheat_mode", 2),
                (str_store_troop_name, s4, ":var_0"),
                (display_message, "str_debug__attempting_to_spawn_s4"),
            (try_end),
            (call_script, "script_cf_select_random_walled_center_with_faction_and_owner_priority_no_siege", ":var_1", ":var_0"),
            (assign, ":var_2", reg0),
            (try_begin),
                (eq, "$cheat_mode", 2),
                (assign, reg7, ":var_2"),
                (str_store_party_name, s7, ":var_2"),
                (display_message, "str_debug__s0_is_spawning_around_party__s7"),
            (try_end),
            (call_script, "script_create_kingdom_hero_party", ":var_0", ":var_2"),
            (party_attach_to_party, "$pout_party", ":var_2"),
            (troop_get_slot, ":var_3", ":var_0", slot_troop_leaded_party),
            (call_script, "script_party_set_ai_state", ":var_3", 7, ":var_2"),
        (else_try),
            (neg|faction_slot_eq, ":var_1", slot_faction_state, 0),
            (try_begin),
                (is_between, ":var_0", "trp_kingdom_1_lord", "trp_knight_1_1"),
                (troop_set_slot, ":var_0", slot_troop_change_to_faction, "fac_commoners"),
            (else_try),
                (store_random_in_range, ":var_4", 0, 100),
                (neg|ge, ":var_4", 10),
                (call_script, "script_cf_get_random_active_faction_except_player_faction_and_faction", ":var_1"),
                (troop_set_slot, ":var_0", slot_troop_change_to_faction, reg0),
            (try_end),
        (try_end),
    (try_end),

]),

(24.000000,
[
    (try_for_range, ":var_0", "p_village_1", "p_salt_mine"),
        (party_slot_eq, ":var_0", slot_village_state, 0),
        (party_get_slot, ":var_1", ":var_0", slot_village_farmer_party),
        (this_or_next|eq, ":var_1", 0),
        (neg|party_is_active, ":var_1"),
        (store_random_in_range, ":var_2", 0, 100),
        (neg|ge, ":var_2", 60),
        (call_script, "script_create_village_farmer_party", ":var_0"),
        (party_set_slot, ":var_0", slot_village_farmer_party, reg0),
    (try_end),

]),

(72.000000,
[
    (call_script, "script_update_trade_good_prices"),
    (try_for_range, ":var_0", "p_town_1", "p_salt_mine"),
        (party_get_slot, ":var_1", ":var_0", slot_town_player_odds),
        (try_begin),
            (gt, ":var_1", 1000),
            (val_mul, ":var_1", 95),
            (val_div, ":var_1", 100),
            (val_max, ":var_1", 1000),
        (else_try),
            (neg|ge, ":var_1", 1000),
            (val_mul, ":var_1", 105),
            (val_div, ":var_1", 100),
            (val_min, ":var_1", 1000),
        (try_end),
        (party_set_slot, ":var_0", slot_town_player_odds, ":var_1"),
    (try_end),

]),

(8.000000,
[
    (try_for_parties, ":var_0"),
        (assign, ":var_1", 0),
        (try_begin),
            (party_slot_eq, ":var_0", slot_party_type, 19),
            (party_is_in_any_town, ":var_0"),
            (party_get_cur_town, ":var_2", ":var_0"),
            (party_slot_eq, ":var_0", slot_party_home_center, ":var_2"),
            (party_get_num_prisoner_stacks, ":var_3", ":var_0"),
            (try_begin),
                (gt, ":var_3", 0),
                (assign, "$g_move_heroes", 1),
                (call_script, "script_party_prisoners_add_party_prisoners", ":var_2", ":var_0"),
            (try_end),
            (remove_party, ":var_0"),
            (assign, ":var_1", 1),
        (try_end),
        (eq, ":var_1", 0),
        (party_slot_eq, ":var_0", slot_party_type, 11),
        (party_is_in_any_town, ":var_0"),
        (store_faction_of_party, ":var_4", ":var_0"),
        (faction_get_slot, ":var_5", ":var_4", slot_faction_num_towns),
        (try_begin),
            (neg|gt, ":var_5", 0),
            (remove_party, ":var_0"),
        (else_try),
            (party_get_cur_town, ":var_2", ":var_0"),
            (store_random_in_range, ":var_6", 0, 100),
            (try_begin),
                (party_slot_eq, ":var_2", slot_town_lord, "trp_player"),
                (game_get_reduce_campaign_ai, ":var_7"),
                (try_begin),
                    (eq, ":var_7", 0),
                    (assign, ":var_8", 35),
                (else_try),
                    (eq, ":var_7", 1),
                    (assign, ":var_8", 45),
                (else_try),
                    (eq, ":var_7", 2),
                    (assign, ":var_8", 60),
                (try_end),
            (else_try),
                (assign, ":var_8", 45),
            (try_end),
            (neg|ge, ":var_6", ":var_8"),
            (assign, ":var_9", 1),
            (try_begin),
                (is_between, ":var_2", "p_town_1", "p_village_1"),
                (neg|party_slot_eq, ":var_2", slot_center_is_besieged_by, -1),
                (assign, ":var_9", 0),
            (try_end),
            (eq, ":var_9", 1),
            (assign, ":var_10", 0),
            (try_begin),
                (party_get_slot, ":var_11", ":var_0", slot_party_ai_state),
                (eq, ":var_11", 13),
                (party_get_slot, ":var_12", ":var_0", slot_party_ai_object),
                (eq, ":var_2", ":var_12"),
                (assign, ":var_10", 1),
            (try_end),
            (assign, ":var_13", -1),
            (try_begin),
                (eq, "$caravan_escort_party_id", ":var_0"),
                (neg|party_is_in_town, ":var_0", "$caravan_escort_destination_town"),
                (assign, ":var_13", "$caravan_escort_destination_town"),
            (else_try),
                (call_script, "script_cf_select_most_profitable_town_at_peace_with_faction_in_trade_route", ":var_2", ":var_4"),
                (assign, ":var_13", reg0),
            (try_end),
            (is_between, ":var_13", "p_town_1", "p_castle_1"),
            (neg|party_is_in_town, ":var_0", ":var_13"),
            (try_begin),
                (eq, ":var_10", 1),
                (str_store_party_name, s7, ":var_2"),
                (call_script, "script_do_merchant_town_trade", ":var_0", ":var_2"),
            (try_end),
            (party_set_ai_behavior, ":var_0", 1),
            (party_set_ai_object, ":var_0", ":var_13"),
            (party_set_flags, ":var_0", 65536, 0),
            (party_set_slot, ":var_0", slot_party_ai_state, 13),
            (party_set_slot, ":var_0", slot_party_ai_object, ":var_13"),
        (try_end),
    (try_end),

]),

(8.000000,
[
    (try_for_parties, ":var_0"),
        (party_slot_eq, ":var_0", slot_party_type, 15),
        (party_is_in_any_town, ":var_0"),
        (party_get_slot, ":var_1", ":var_0", slot_party_home_center),
        (party_get_cur_town, ":var_2", ":var_0"),
        (assign, ":var_3", 1),
        (try_begin),
            (is_between, ":var_2", "p_town_1", "p_village_1"),
            (neg|party_slot_eq, ":var_2", slot_center_is_besieged_by, -1),
            (assign, ":var_3", 0),
        (try_end),
        (eq, ":var_3", 1),
        (try_begin),
            (eq, ":var_2", ":var_1"),
            (call_script, "script_do_party_center_trade", ":var_0", ":var_1", 25),
            (store_faction_of_party, ":var_4", ":var_2"),
            (party_set_faction, ":var_0", ":var_4"),
            (party_get_slot, ":var_5", ":var_1", slot_village_market_town),
            (party_set_slot, ":var_0", slot_party_ai_object, ":var_5"),
            (party_set_slot, ":var_0", slot_party_ai_state, 13),
            (party_set_ai_behavior, ":var_0", 1),
            (party_set_ai_object, ":var_0", ":var_5"),
        (else_try),
            (try_begin),
                (party_get_slot, ":var_6", ":var_0", slot_party_ai_object),
                (eq, ":var_2", ":var_6"),
                (call_script, "script_do_party_center_trade", ":var_0", ":var_6", 25),
                (assign, ":var_7", reg0),
                (party_get_slot, ":var_8", ":var_6", slot_center_accumulated_tariffs),
                (party_get_slot, ":var_9", ":var_6", slot_town_prosperity),
                (assign, ":var_10", ":var_7"),
                (val_mul, ":var_10", ":var_9"),
                (val_div, ":var_10", 300),
                (val_div, ":var_10", 20),
                (val_add, ":var_8", ":var_10"),
                (try_begin),
                    (ge, "$cheat_mode", 3),
                    (assign, reg4, ":var_10"),
                    (str_store_party_name, s4, ":var_6"),
                    (assign, reg5, ":var_8"),
                    (display_message, "@{!}New tariffs at {s4} = {reg4}, total = {reg5}"),
                (try_end),
                (party_set_slot, ":var_6", slot_center_accumulated_tariffs, ":var_8"),
                (party_get_slot, ":var_11", ":var_6", slot_party_food_store),
                (call_script, "script_center_get_food_store_limit", ":var_6"),
                (assign, ":var_12", reg0),
                (val_add, ":var_11", 1000),
                (val_min, ":var_11", ":var_12"),
                (party_set_slot, ":var_6", slot_party_food_store, ":var_11"),
                (try_begin),
                    (store_random_in_range, ":var_13", 0, 100),
                    (neg|ge, ":var_13", 35),
                    (call_script, "script_change_center_prosperity", ":var_1", 1),
                    (val_add, "$newglob_total_prosperity_from_village_trade", 1),
                (try_end),
            (try_end),
            (party_set_slot, ":var_0", slot_party_ai_object, ":var_1"),
            (party_set_slot, ":var_0", slot_party_ai_state, 13),
            (party_set_ai_behavior, ":var_0", 1),
            (party_set_ai_object, ":var_0", ":var_1"),
        (try_end),
    (try_end),

]),

(2.000000,
[
    (try_for_range, ":var_0", "p_castle_1", "p_village_1"),
        (party_slot_eq, ":var_0", slot_center_is_besieged_by, -1),
        (party_get_slot, ":var_1", ":var_0", slot_party_food_store),
        (val_add, ":var_1", 100),
        (call_script, "script_center_get_food_store_limit", ":var_0"),
        (assign, ":var_2", reg0),
        (val_min, ":var_1", ":var_2"),
        (party_set_slot, ":var_0", slot_party_food_store, ":var_1"),
    (try_end),

]),

(0.500000,
[
    (try_for_range, ":var_0", "trp_npc_adonja", "trp_heroes_end"),
        (troop_slot_eq, ":var_0", slot_troop_occupation, 2),
        (troop_get_slot, ":var_1", ":var_0", slot_troop_leaded_party),
        (gt, ":var_1", 0),
        (try_begin),
            (party_is_active, ":var_1"),
            (try_begin),
                (get_party_ai_current_behavior, ":var_2", ":var_1"),
                (eq, ":var_2", 5),
                (assign, ":var_3", 1),
                (try_begin),
                    (this_or_next|troop_slot_eq, ":var_0", slot_lord_reputation_type, 7),
                    (troop_slot_eq, ":var_0", slot_lord_reputation_type, 1),
                    (get_party_ai_current_object, ":var_4", ":var_1"),
                    (party_is_active, ":var_4"),
                    (party_get_battle_opponent, ":var_5", ":var_4"),
                    (party_is_active, ":var_5"),
                    (assign, ":var_3", 0),
                (try_end),
                (eq, ":var_3", 1),
                (store_faction_of_party, ":var_6", ":var_1"),
                (party_get_slot, ":var_7", ":var_1", slot_party_commander_party),
                (faction_get_slot, ":var_8", ":var_6", slot_faction_marshall),
                (neg|eq, ":var_8", ":var_0"),
                (assign, ":var_3", 1),
                (try_begin),
                    (ge, ":var_8", 0),
                    (troop_get_slot, ":var_9", ":var_8", slot_troop_leaded_party),
                    (party_is_active, ":var_9", 0),
                    (eq, ":var_7", ":var_9"),
                    (assign, ":var_3", 0),
                (try_end),
                (eq, ":var_3", 1),
                (assign, ":var_10", 0),
                (try_for_range, ":var_11", "p_town_1", "p_village_1"),
                    (eq, ":var_10", 0),
                    (party_slot_eq, ":var_11", slot_center_is_besieged_by, -1),
                    (store_faction_of_party, ":var_12", ":var_11"),
                    (store_relation, ":var_13", ":var_12", ":var_6"),
                    (gt, ":var_13", 0),
                    (store_distance_to_party_from_party, ":var_14", ":var_1", ":var_11"),
                    (neg|ge, ":var_14", 20),
                    (party_get_position, pos1, ":var_1"),
                    (party_get_position, pos2, ":var_11"),
                    (neg|position_is_behind_position, 2, 1),
                    (call_script, "script_party_set_ai_state", ":var_1", 14, ":var_11"),
                    (assign, ":var_10", 1),
                (try_end),
            (try_end),
        (else_try),
            (troop_set_slot, ":var_0", slot_troop_leaded_party, -1),
        (try_end),
    (try_end),

]),

(0.500000,
[
    (store_current_hours, ":var_0"),
    (store_mod, ":var_1", ":var_0", 11),
    (store_sub, ":var_2", ":var_0", 5),
    (party_get_num_companions, ":var_3", "p_main_party"),
    (party_get_num_prisoners, ":var_4", "p_main_party"),
    (val_add, ":var_3", ":var_4"),
    (convert_to_fixed_point, ":var_3"),
    (store_sqrt, ":var_5", ":var_3"),
    (convert_from_fixed_point, ":var_5"),
    (try_begin),
        (eq, ":var_1", 0),
        (try_for_range, ":var_6", "fac_player_supporters_faction", "fac_kingdoms_end"),
            (faction_get_slot, ":var_7", ":var_6", slot_faction_player_alarm),
            (val_sub, ":var_7", 1),
            (val_max, ":var_7", 0),
            (faction_set_slot, ":var_6", slot_faction_player_alarm, ":var_7"),
        (try_end),
    (try_end),
    (eq, "$g_player_is_captive", 0),
    (try_for_range, ":var_8", "p_town_1", "p_salt_mine"),
        (store_faction_of_party, ":var_6", ":var_8"),
        (store_relation, ":var_9", ":var_6", "fac_player_supporters_faction"),
        (neg|ge, ":var_9", 0),
        (store_distance_to_party_from_party, ":var_10", "p_main_party", ":var_8"),
        (neg|ge, ":var_10", 5),
        (store_mul, ":var_11", ":var_10", ":var_10"),
        (store_sub, ":var_12", 20, ":var_11"),
        (store_sub, ":var_13", 20, ":var_9"),
        (store_mul, ":var_14", ":var_12", ":var_13"),
        (val_mul, ":var_14", ":var_5"),
        (store_div, ":var_15", ":var_14", 10),
        (store_random_in_range, ":var_16", 0, 1000),
        (neg|ge, ":var_16", ":var_15"),
        (faction_get_slot, ":var_7", ":var_6", slot_faction_player_alarm),
        (val_add, ":var_7", 1),
        (val_min, ":var_7", 100),
        (faction_set_slot, ":var_6", slot_faction_player_alarm, ":var_7"),
        (try_begin),
            (neg|party_slot_ge, ":var_8", slot_center_last_player_alarm_hour, ":var_2"),
            (str_store_party_name_link, s1, ":var_8"),
            (display_message, "@Your party is spotted by {s1}."),
            (party_set_slot, ":var_8", slot_center_last_player_alarm_hour, ":var_0"),
        (try_end),
    (try_end),

]),

(14.000000,
[
    (eq, "$g_player_is_captive", 0),
    (party_get_num_companion_stacks, ":var_0", "p_main_party"),
    (assign, ":var_1", 0),
    (try_for_range, ":var_2", 0, ":var_0"),
        (party_stack_get_size, ":var_3", "p_main_party", ":var_2"),
        (val_add, ":var_1", ":var_3"),
    (try_end),
    (val_div, ":var_1", 3),
    (try_begin),
        (eq, ":var_1", 0),
        (val_add, ":var_1", 1),
    (try_end),
    (try_begin),
        (assign, ":var_4", 0),
        (try_for_range, ":var_5", "itm_smoked_fish", "itm_siege_supply"),
            (call_script, "script_cf_player_has_item_without_modifier", ":var_5", 41),
            (val_add, ":var_4", 1),
        (try_end),
        (try_begin),
            (ge, ":var_4", 6),
            (unlock_achievement, 36),
        (try_end),
    (try_end),
    (assign, ":var_6", ":var_1"),
    (assign, ":var_7", 0),
    (try_for_range, ":var_8", 0, ":var_6"),
        (assign, ":var_9", 0),
        (try_for_range, ":var_10", "itm_smoked_fish", "itm_siege_supply"),
            (item_set_slot, ":var_10", slot_item_is_checked, 0),
            (call_script, "script_cf_player_has_item_without_modifier", ":var_10", 41),
            (val_add, ":var_9", 1),
        (try_end),
        (try_begin),
            (gt, ":var_9", 0),
            (store_random_in_range, ":var_11", 0, ":var_9"),
            (call_script, "script_consume_food", ":var_11"),
        (else_try),
            (eq, ":var_7", 0),
            (display_message, "@Party has nothing to eat!", 0xFF0000),
            (call_script, "script_change_player_party_morale", -3),
            (assign, ":var_7", 1),
            (try_begin),
                (call_script, "script_party_count_fit_regulars", "p_main_party"),
                (gt, reg0, 0),
                (call_script, "script_objectionable_action", 2, "str_men_hungry"),
            (try_end),
        (try_end),
    (try_end),

]),

(24.000000,
[
    (troop_get_inventory_capacity, ":var_0", "trp_player"),
    (try_for_range, ":var_1", 0, ":var_0"),
        (troop_get_inventory_slot, ":var_2", "trp_player", ":var_1"),
        (this_or_next|eq, ":var_2", "itm_cattle_meat"),
        (this_or_next|eq, ":var_2", "itm_chicken"),
        (eq, ":var_2", "itm_pork"),
        (troop_get_inventory_slot_modifier, ":var_3", "trp_player", ":var_1"),
        (try_begin),
            (ge, ":var_3", 37),
            (neg|ge, ":var_3", 41),
            (val_add, ":var_3", 1),
            (troop_set_inventory_slot_modifier, "trp_player", ":var_1", ":var_3"),
        (else_try),
            (neg|ge, ":var_3", 37),
            (troop_set_inventory_slot_modifier, "trp_player", ":var_1", 37),
        (try_end),
    (try_end),

]),

(72.000000,
[

]),

(0.000000,
[
    (troop_get_inventory_slot, ":var_0", "trp_player", 8),
    (assign, ":var_1", -1),
    (try_begin),
        (eq, "$g_player_icon_state", 0),
        (try_begin),
            (ge, ":var_0", 0),
            (assign, ":var_1", "icon_player_horseman"),
        (else_try),
            (assign, ":var_1", "icon_player"),
        (try_end),
    (else_try),
        (eq, "$g_player_icon_state", 1),
        (assign, ":var_1", "icon_camp"),
    (else_try),
        (eq, "$g_player_icon_state", 2),
        (assign, ":var_1", "icon_ship"),
    (try_end),
    (neg|eq, ":var_1", "$g_player_party_icon"),
    (assign, "$g_player_party_icon", ":var_1"),
    (party_set_icon, "p_main_party", ":var_1"),

]),

(2.000000,
[
    (store_troop_gold, ":var_0", "trp_player"),
    (store_div, ":var_1", ":var_0", 100),
    (troop_get_inventory_capacity, ":var_2", "trp_player"),
    (try_for_range, ":var_3", 0, ":var_2"),
        (troop_get_inventory_slot, ":var_4", "trp_player", ":var_3"),
        (ge, ":var_4", 0),
        (try_begin),
            (is_between, ":var_4", "itm_spice", "itm_baggage_train"),
            (store_item_value, ":var_5", ":var_4"),
            (val_add, ":var_0", ":var_5"),
        (try_end),
    (try_end),
    (val_clamp, ":var_1", 0, 100),
    (party_set_bandit_attraction, "p_main_party", ":var_1"),

]),

(3.000000,
[
    (try_for_range, ":var_0", "p_town_1", "p_village_1"),
        (faction_slot_eq, "fac_player_supporters_faction", slot_faction_state, 2),
        (store_faction_of_party, ":var_1", ":var_0"),
        (eq, ":var_1", "fac_player_supporters_faction"),
        (call_script, "script_activate_player_faction", "trp_player"),
    (try_end),

]),

(6.000000,
[
    (gt, "$g_prisoner_recruit_troop_id", 0),
    (gt, "$g_prisoner_recruit_size", 0),
    (gt, "$g_prisoner_recruit_last_time", 0),
    (is_currently_night),
    (try_begin),
        (store_skill_level, ":var_0", "skl_leadership", "trp_player"),
        (val_mul, ":var_0", 5),
        (store_sub, ":var_1", 66, ":var_0"),
        (gt, ":var_1", 0),
        (assign, ":var_2", 0),
        (try_for_range, ":var_3", 0, "$g_prisoner_recruit_size"),
            (store_random_in_range, ":var_4", 0, 100),
            (neg|ge, ":var_4", ":var_1"),
            (val_add, ":var_2", 1),
        (try_end),
        (party_remove_members, "p_main_party", "$g_prisoner_recruit_troop_id", ":var_2"),
        (assign, ":var_2", reg0),
        (gt, ":var_2", 0),
        (try_begin),
            (gt, ":var_2", 1),
            (assign, reg2, 1),
        (else_try),
            (assign, reg2, 0),
        (try_end),
        (assign, reg1, ":var_2"),
        (str_store_troop_name_by_count, s1, "$g_prisoner_recruit_troop_id", ":var_2"),
        (display_log_message, "@{reg1} {s1} {reg2?have:has} escaped from your party during the night."),
    (try_end),
    (assign, "$g_prisoner_recruit_troop_id", 0),
    (assign, "$g_prisoner_recruit_size", 0),

]),

(24.000000,
[
    (neg|eq, "$g_ransom_offer_rejected", 1),
    (call_script, "script_offer_ransom_amount_to_player_for_prisoners_in_party", "p_main_party"),
    (eq, reg0, 0),
    (assign, ":var_0", "p_village_1"),
    (try_for_range, ":var_1", "p_town_1", ":var_0"),
        (party_slot_eq, ":var_1", slot_town_lord, "trp_player"),
        (call_script, "script_offer_ransom_amount_to_player_for_prisoners_in_party", ":var_1"),
        (eq, reg0, 1),
        (assign, ":var_0", 0),
    (try_end),

]),

(72.000000,
[
    (assign, "$g_ransom_offer_rejected", 0),
    (try_for_range, ":var_0", "p_town_1", "p_village_1"),
        (party_get_slot, ":var_1", ":var_0", slot_town_lord),
        (gt, ":var_1", 0),
        (party_get_num_prisoner_stacks, ":var_2", ":var_0"),
        (try_for_range_backwards, ":var_3", 0, ":var_2"),
            (party_prisoner_stack_get_troop_id, ":var_4", ":var_0", ":var_3"),
            (troop_is_hero, ":var_4"),
            (troop_slot_eq, ":var_4", slot_troop_occupation, 2),
            (store_random_in_range, ":var_5", 0, 100),
            (try_begin),
                (neg|gt, ":var_5", 10),
                (call_script, "script_calculate_ransom_amount_for_troop", ":var_4"),
                (assign, ":var_6", reg0),
                (troop_get_slot, ":var_7", ":var_1", slot_troop_wealth),
                (val_add, ":var_7", ":var_6"),
                (troop_set_slot, ":var_1", slot_troop_wealth, ":var_7"),
                (party_remove_prisoners, ":var_0", ":var_4", 1),
                (call_script, "script_remove_troop_from_prison", ":var_4"),
                (store_troop_faction, ":var_8", ":var_1"),
                (store_troop_faction, ":var_9", ":var_4"),
                (str_store_troop_name, s1, ":var_4"),
                (str_store_faction_name, s2, ":var_8"),
                (str_store_faction_name, s3, ":var_9"),
                (try_begin),
                    (this_or_next|eq, ":var_9", "$players_kingdom"),
                    (eq, "$g_option_important_news", 0),
                    (call_script, "script_get_message_color", 3, ":var_4"),
                    (display_log_message, "@{s1} of the {s3} has been released from captivity.", reg20),
                (try_end),
            (try_end),
        (try_end),
    (try_end),

]),

(72.000000,
[
    (call_script, "script_update_mercenary_units_of_towns"),
    (call_script, "script_update_ransom_brokers"),
    (call_script, "script_update_tavern_travellers"),
    (call_script, "script_update_tavern_minstrels"),
    (call_script, "script_update_booksellers"),
    (call_script, "script_update_villages_infested_by_bandits"),
    (try_for_range, ":var_0", "p_village_1", "p_salt_mine"),
        (call_script, "script_update_volunteer_troops_in_village", ":var_0"),
        (call_script, "script_update_npc_volunteer_troops_in_village", ":var_0"),
    (try_end),

]),

(24.000000,
[
    (call_script, "script_update_other_taverngoers"),

]),

(36.000000,
[
    (try_for_range, ":var_0", "p_town_1", "p_salt_mine"),
        (this_or_next|party_slot_eq, ":var_0", slot_party_type, 3),
        (party_slot_eq, ":var_0", slot_party_type, 4),
        (call_script, "script_center_remove_walker_type_from_walkers", ":var_0", 1),
        (call_script, "script_center_remove_walker_type_from_walkers", ":var_0", 2),
        (store_random_in_range, ":var_1", 0, 100),
        (try_begin),
            (neg|ge, ":var_1", 70),
            (neg|party_slot_ge, ":var_0", slot_town_prosperity, 180),
            (call_script, "script_cf_center_get_free_walker", ":var_0"),
            (call_script, "script_center_set_walker_to_type", ":var_0", reg0, 1),
        (try_end),
    (try_end),

]),

(12.000000,
[
    (try_for_range, ":var_0", "p_town_1", "p_salt_mine"),
        (party_get_slot, ":var_1", ":var_0", slot_center_current_improvement),
        (gt, ":var_1", 0),
        (party_get_slot, ":var_2", ":var_0", slot_center_improvement_end_hour),
        (store_current_hours, ":var_3"),
        (ge, ":var_3", ":var_2"),
        (call_script, "script_center_base_income_change", ":var_0", ":var_1", 1),
        (party_set_slot, ":var_0", slot_center_current_improvement, 0),
        (call_script, "script_get_improvement_details", ":var_1", ":var_0"),
        (try_begin),
            (party_slot_eq, ":var_0", slot_town_lord, "trp_player"),
            (str_store_party_name, s4, ":var_0"),
            (val_add, "$g_improvements_built", 1),
            (display_log_message, "@Building of {s10} in {s4} has been completed."),
            (play_sound, "snd_bellchant"),
        (try_end),
    (try_end),

]),

(24.000000,
[
    (assign, ":var_0", 0),
    (try_for_range, ":var_1", "p_town_1", "p_castle_1"),
        (party_get_slot, ":var_2", ":var_1", slot_town_has_tournament),
        (try_begin),
            (eq, ":var_2", 1),
            (call_script, "script_fill_tournament_participants_troop", ":var_1", 0),
            (call_script, "script_sort_tournament_participant_troops"),
            (call_script, "script_get_num_tournament_participants"),
            (store_sub, ":var_3", reg0, 1),
            (call_script, "script_remove_tournament_participants_randomly", ":var_3"),
            (call_script, "script_sort_tournament_participant_troops"),
            (troop_get_slot, ":var_4", "trp_tournament_participants", slot_troop_relations_begin),
            (try_begin),
                (is_between, ":var_4", "trp_npc_adonja", "trp_knight_1_1_wife"),
                (str_store_troop_name_link, s1, ":var_4"),
                (str_store_party_name_link, s2, ":var_1"),
                (display_message, "@{s1} has won the tournament at {s2}."),
                (call_script, "script_change_troop_renown", ":var_4", 20),
            (try_end),
        (try_end),
        (val_sub, ":var_2", 1),
        (val_max, ":var_2", 0),
        (party_set_slot, ":var_1", slot_town_has_tournament, ":var_2"),
        (try_begin),
            (gt, ":var_2", 0),
            (val_add, ":var_0", 1),
        (try_end),
    (try_end),
    (store_current_hours, ":var_5"),
    (call_script, "script_game_get_date_text", 0, ":var_5"),
    (assign, ":var_6", reg1),
    (try_begin),
        (eq, ":var_6", 4),
        (party_set_slot, "p_castle_noldor", slot_town_has_tournament, 0),
    (else_try),
        (eq, ":var_6", 1),
        (party_set_slot, "p_castle_noldor", slot_town_has_tournament, 1),
    (try_end),
    (try_for_range, ":var_1", "p_town_1", "p_salt_mine"),
        (this_or_next|party_slot_eq, ":var_1", slot_party_type, 3),
        (party_slot_eq, ":var_1", slot_party_type, 4),
        (party_get_slot, ":var_7", ":var_1", slot_center_has_bandits),
        (try_begin),
            (neg|gt, ":var_7", 0),
            (assign, ":var_8", 0),
            (try_begin),
                (check_quest_active, "qst_deal_with_night_bandits"),
                (quest_slot_eq, "qst_deal_with_night_bandits", 1, ":var_1"),
                (neg|check_quest_succeeded, "qst_deal_with_night_bandits"),
                (assign, ":var_8", 1),
            (else_try),
                (store_random_in_range, ":var_9", 0, 100),
                (neg|ge, ":var_9", 3),
                (assign, ":var_8", 1),
            (try_end),
            (try_begin),
                (eq, ":var_8", 1),
                (store_random_in_range, ":var_9", 0, 9),
                (try_begin),
                    (eq, ":var_9", 0),
                    (assign, ":var_10", "trp_bandit"),
                (else_try),
                    (eq, ":var_9", 1),
                    (assign, ":var_10", "trp_brigand"),
                (else_try),
                    (eq, ":var_9", 2),
                    (assign, ":var_10", "trp_forest_bandit"),
                (else_try),
                    (eq, ":var_9", 3),
                    (assign, ":var_10", "trp_rb_thief"),
                (else_try),
                    (eq, ":var_9", 4),
                    (assign, ":var_10", "trp_rb_guildsman"),
                (else_try),
                    (eq, ":var_9", 5),
                    (assign, ":var_10", "trp_slave_hunter"),
                (else_try),
                    (eq, ":var_9", 6),
                    (assign, ":var_10", "trp_dshar_assassin"),
                (else_try),
                    (eq, ":var_9", 7),
                    (assign, ":var_10", "trp_snake_armsman"),
                (else_try),
                    (assign, ":var_10", "trp_outlaw_leader"),
                (try_end),
                (party_set_slot, ":var_1", slot_center_has_bandits, ":var_10"),
                (try_begin),
                    (eq, "$cheat_mode", 1),
                    (str_store_party_name, s1, ":var_1"),
                    (display_message, "@{!}{s1} is infested by bandits (at night)."),
                (try_end),
            (try_end),
        (else_try),
            (try_begin),
                (assign, ":var_11", 40),
                (try_begin),
                    (party_slot_eq, ":var_1", slot_party_type, 3),
                    (assign, ":var_11", 20),
                (try_end),
                (store_random_in_range, ":var_9", 0, 100),
                (neg|ge, ":var_9", ":var_11"),
                (party_set_slot, ":var_1", slot_center_has_bandits, 0),
                (try_begin),
                    (eq, "$cheat_mode", 1),
                    (str_store_party_name, s1, ":var_1"),
                    (display_message, "@{s1} is no longer infested by bandits (at night)."),
                (try_end),
            (try_end),
        (try_end),
    (try_end),
    (try_for_range, ":var_12", "fac_player_supporters_faction", "fac_kingdoms_end"),
        (faction_slot_eq, ":var_12", slot_faction_ai_state, 6),
        (faction_get_slot, ":var_13", ":var_12", slot_faction_ai_object),
        (is_between, ":var_13", "p_town_1", "p_castle_1"),
        (party_slot_ge, ":var_13", slot_town_has_tournament, 1),
        (party_set_slot, ":var_13", slot_town_has_tournament, 2),
    (try_end),
    (try_begin),
        (neg|ge, ":var_0", 3),
        (store_random_in_range, ":var_9", 0, 100),
        (neg|ge, ":var_9", 30),
        (store_random_in_range, ":var_14", "p_town_1", "p_castle_1"),
        (store_random_in_range, ":var_15", 12, 15),
        (party_set_slot, ":var_14", slot_town_has_tournament, ":var_15"),
        (try_begin),
            (eq, "$cheat_mode", 1),
            (str_store_party_name, s1, ":var_14"),
            (display_message, "@{!}{s1} is holding a tournament."),
        (try_end),
    (try_end),

]),

(3.000000,
[
    (assign, "$g_player_tournament_placement", 0),

]),

(8.000000,
[

]),

(1.000000,
[
    (neg|map_free),
    (is_currently_night),
    (is_between, "$g_last_rest_center", "p_town_1", "p_salt_mine"),
    (neg|party_slot_eq, "$g_last_rest_center", slot_town_lord, "trp_player"),
    (store_faction_of_party, ":var_0", "$g_last_rest_center"),
    (neg|eq, ":var_0", "fac_player_supporters_faction"),
    (store_current_hours, ":var_1"),
    (ge, ":var_1", "$g_last_rest_payment_until"),
    (store_add, "$g_last_rest_payment_until", ":var_1", 24),
    (store_troop_gold, ":var_2", "trp_player"),
    (party_get_num_companions, ":var_3", "p_main_party"),
    (store_div, ":var_4", ":var_3", 4),
    (val_add, ":var_4", 1),
    (try_begin),
        (ge, ":var_2", ":var_4"),
        (display_message, "@You pay for accommodation."),
        (troop_remove_gold, "trp_player", ":var_4"),
    (else_try),
        (gt, ":var_2", 0),
        (troop_remove_gold, "trp_player", ":var_2"),
    (try_end),

]),

(16.000000,
[
    (call_script, "script_spawn_bandits"),
    (call_script, "script_spawn_red_brotherhood"),

]),

(33.000000,
[
    (call_script, "script_spawn_snake_cult", 0),
    (call_script, "script_spawn_heretics", 0),
    (call_script, "script_spawn_jatu", 0),
    (call_script, "script_spawn_mystmountain", 0),
    (call_script, "script_spawn_errant_knights"),
    (call_script, "script_spawn_vanskerry"),
    (call_script, "script_spawn_singal_raiders"),
    (call_script, "script_spawn_noldor", 0),

]),

(34.000000,
[
    (call_script, "script_update_party_creation_random_limits"),
    (call_script, "script_determine_victory_conditions_and_text", 0),

]),

(24.000000,
[
    (assign, ":var_0", 0),
    (try_for_range, ":var_1", "fac_player_supporters_faction", "fac_kingdoms_end"),
        (faction_set_slot, ":var_1", slot_faction_number_of_parties, 0),
    (try_end),
    (try_for_parties, ":var_2"),
        (store_faction_of_party, ":var_3", ":var_2"),
        (is_between, ":var_3", "fac_player_supporters_faction", "fac_kingdoms_end"),
        (this_or_next|is_between, ":var_2", "p_town_1", "p_salt_mine"),
        (party_slot_eq, ":var_2", slot_party_type, 13),
        (faction_get_slot, ":var_4", ":var_3", slot_faction_number_of_parties),
        (val_add, ":var_4", 1),
        (faction_set_slot, ":var_3", slot_faction_number_of_parties, ":var_4"),
    (try_end),
    (try_for_range, ":var_1", "fac_player_supporters_faction", "fac_kingdoms_end"),
        (faction_slot_eq, ":var_1", slot_faction_state, 0),
        (val_add, ":var_0", 1),
        (faction_slot_eq, ":var_1", slot_faction_number_of_parties, 0),
        (assign, ":var_5", 0),
        (try_begin),
            (eq, ":var_1", "fac_player_supporters_faction"),
            (try_begin),
                (neg|gt, "$supported_pretender", 0),
                (faction_set_slot, ":var_1", slot_faction_state, 2),
                (assign, ":var_5", 1),
            (try_end),
        (else_try),
            (neg|eq, "$players_kingdom", ":var_1"),
            (faction_set_slot, ":var_1", slot_faction_state, 1),
            (try_for_parties, ":var_2"),
                (store_faction_of_party, ":var_3", ":var_2"),
                (eq, ":var_3", ":var_1"),
                (party_get_slot, ":var_6", ":var_2", slot_party_home_center),
                (try_begin),
                    (gt, ":var_6", 0),
                    (store_faction_of_party, ":var_7", ":var_6"),
                    (party_set_faction, ":var_2", ":var_7"),
                (else_try),
                    (party_set_faction, ":var_2", "fac_outlaws"),
                    (party_set_ai_behavior, ":var_2", 2),
                    (party_set_ai_object, ":var_2", "p_main_party"),
                (try_end),
            (try_end),
            (assign, ":var_8", -1),
            (try_for_range, ":var_9", "trp_kingdom_1_pretender", "trp_knight_1_1_wife"),
                (troop_slot_eq, ":var_9", slot_troop_original_faction, ":var_1"),
                (assign, ":var_8", ":var_9"),
            (try_end),
            (try_begin),
                (is_between, ":var_8", "trp_kingdom_1_pretender", "trp_knight_1_1_wife"),
                (neg|eq, ":var_8", "$supported_pretender"),
                (troop_set_slot, ":var_8", slot_troop_cur_center, 0),
            (try_end),
            (assign, ":var_5", 1),
            (try_begin),
                (eq, "$players_oath_renounced_against_kingdom", ":var_1"),
                (assign, "$players_oath_renounced_against_kingdom", 0),
                (assign, "$players_oath_renounced_given_center", 0),
                (assign, "$players_oath_renounced_begin_time", 0),
                (call_script, "script_add_notification_menu", "mnu_notification_oath_renounced_faction_defeated", ":var_1", 0),
            (try_end),
            (call_script, "script_add_notification_menu", "mnu_notification_faction_defeated", ":var_1", 0),
        (try_end),
        (try_begin),
            (eq, ":var_5", 1),
            (val_sub, ":var_0", 1),
        (try_end),
        (try_for_range, ":var_10", "fac_player_supporters_faction", "fac_kingdoms_end"),
            (call_script, "script_update_faction_notes", ":var_10"),
        (try_end),
    (try_end),
    (try_begin),
        (eq, ":var_0", 1),
        (assign, "$g_one_faction_left_notification_shown", 1),
        (call_script, "script_determine_victory_conditions_and_text", 0),
        (neg|gt, reg7, 30),
        (neg|gt, reg8, 30),
        (neg|gt, reg9, 30),
        (neg|gt, reg10, 30),
        (eq, "$g_win_pop", 0),
        (store_relation, ":var_11", "fac_noldor_elves", "fac_player_faction"),
        (ge, ":var_11", 30),
        (eq, reg4, 0),
        (try_for_range, ":var_1", "fac_player_supporters_faction", "fac_kingdoms_end"),
            (faction_slot_eq, ":var_1", slot_faction_state, 0),
            (assign, "$g_win_pop", 1),
            (call_script, "script_add_notification_menu", "mnu_notification_one_faction_left", ":var_1", 0),
        (try_end),
    (try_end),

]),

(3.000000,
[
    (try_begin),
        (is_between, "$g_player_court", "p_town_1", "p_salt_mine"),
        (store_faction_of_party, ":var_0", "$g_player_court"),
        (neg|eq, ":var_0", "fac_player_supporters_faction"),
        (call_script, "script_add_notification_menu", "mnu_notification_court_lost", 0, 0),
    (else_try),
        (neg|ge, "$g_player_court", "p_town_1"),
        (this_or_next|faction_slot_eq, "fac_player_supporters_faction", slot_faction_leader, "trp_player"),
        (gt, "$g_player_minister", 0),
        (assign, ":var_1", 0),
        (try_for_range, ":var_2", "p_town_1", "p_village_1"),
            (eq, ":var_1", 0),
            (store_faction_of_party, ":var_0", ":var_2"),
            (eq, ":var_0", "fac_player_supporters_faction"),
            (assign, ":var_1", ":var_2"),
        (try_end),
        (ge, ":var_1", 1),
        (call_script, "script_add_notification_menu", "mnu_notification_court_lost", 0, 0),
    (try_end),
    (try_for_parties, ":var_3"),
        (gt, ":var_3", "p_spawn_points_end"),
        (party_get_template_id, ":var_4", ":var_3"),
        (is_between, ":var_4", "pt_steppe_bandits", "pt_forest_outcasts"),
        (party_template_get_slot, ":var_5", ":var_4", slot_party_template_lair_party),
        (try_begin),
            (gt, ":var_5", "p_spawn_points_end"),
            (store_distance_to_party_from_party, ":var_6", ":var_3", ":var_5"),
            (gt, ":var_6", 30),
            (party_set_ai_behavior, ":var_3", 6),
            (party_get_position, pos5, ":var_5"),
            (party_set_ai_target_position, ":var_3", pos5),
        (else_try),
            (get_party_ai_behavior, ":var_7", ":var_3"),
            (eq, ":var_7", 6),
            (try_begin),
                (gt, ":var_5", "p_spawn_points_end"),
                (store_distance_to_party_from_party, ":var_6", ":var_3", ":var_5"),
                (neg|ge, ":var_6", 3),
                (party_set_ai_behavior, ":var_3", 3),
                (party_template_get_slot, ":var_8", ":var_4", slot_party_template_lair_spawnpoint),
                (party_set_ai_object, ":var_3", ":var_8"),
                (party_set_ai_patrol_radius, ":var_3", 45),
            (else_try),
                (neg|ge, ":var_5", "p_spawn_points_end"),
                (party_set_ai_behavior, ":var_3", 3),
                (party_template_get_slot, ":var_8", ":var_4", slot_party_template_lair_spawnpoint),
                (party_set_ai_object, ":var_3", ":var_8"),
                (party_set_ai_patrol_radius, ":var_3", 45),
            (try_end),
        (try_end),
    (try_end),
    (try_begin),
        (troop_get_slot, ":var_9", "trp_player", slot_troop_betrothed),
        (gt, ":var_9", 0),
        (neg|check_quest_active, "qst_wed_betrothed"),
        (neg|check_quest_active, "qst_wed_betrothed_female"),
        (str_store_troop_name, s5, ":var_9"),
        (display_message, "@Betrothal to {s5} expires"),
        (troop_set_slot, "trp_player", slot_troop_betrothed, -1),
        (troop_set_slot, ":var_9", slot_troop_betrothed, -1),
    (try_end),

]),

(168.000000,
[
    (troop_get_slot, ":var_0", "trp_player", slot_troop_renown),
    (store_div, ":var_1", ":var_0", 200),
    (val_sub, ":var_0", ":var_1"),
    (troop_set_slot, "trp_player", slot_troop_renown, ":var_0"),

]),

(1.000000,
[
    (neg|map_free),
    (gt, "$g_player_reading_book", 0),
    (player_has_item, "$g_player_reading_book"),
    (store_attribute_level, ":var_0", "trp_player", ca_intelligence),
    (item_get_slot, ":var_1", "$g_player_reading_book", slot_item_intelligence_requirement),
    (neg|gt, ":var_1", ":var_0"),
    (item_get_slot, ":var_2", "$g_player_reading_book", slot_item_book_reading_progress),
    (item_get_slot, ":var_3", "$g_player_reading_book", slot_item_book_read),
    (eq, ":var_3", 0),
    (val_add, ":var_2", 7),
    (item_set_slot, "$g_player_reading_book", slot_item_book_reading_progress, ":var_2"),
    (ge, ":var_2", 1000),
    (item_set_slot, "$g_player_reading_book", slot_item_book_read, 1),
    (str_store_item_name, s1, "$g_player_reading_book"),
    (str_clear, s2),
    (try_begin),
        (eq, "$g_player_reading_book", "itm_book_tactics"),
        (troop_raise_skill, "trp_player", "skl_tactics", 1),
        (str_store_string, s2, "@ Your tactics skill has increased by 1."),
    (else_try),
        (eq, "$g_player_reading_book", "itm_book_persuasion"),
        (troop_raise_skill, "trp_player", "skl_persuasion", 1),
        (str_store_string, s2, "@ Your persuasion skill has increased by 1."),
    (else_try),
        (eq, "$g_player_reading_book", "itm_book_leadership"),
        (troop_raise_skill, "trp_player", "skl_leadership", 1),
        (str_store_string, s2, "@ Your leadership skill has increased by 1."),
    (else_try),
        (eq, "$g_player_reading_book", "itm_book_intelligence"),
        (troop_raise_attribute, "trp_player", ca_intelligence, 1),
        (str_store_string, s2, "@ Your intelligence has increased by 1."),
    (else_try),
        (eq, "$g_player_reading_book", "itm_book_trade"),
        (troop_raise_skill, "trp_player", "skl_trade", 1),
        (str_store_string, s2, "@ Your trade skill has increased by 1."),
    (else_try),
        (eq, "$g_player_reading_book", "itm_book_weapon_mastery"),
        (troop_raise_skill, "trp_player", "skl_weapon_master", 1),
        (str_store_string, s2, "@ Your weapon master skill has increased by 1."),
    (else_try),
        (eq, "$g_player_reading_book", "itm_book_engineering"),
        (troop_raise_skill, "trp_player", "skl_engineer", 1),
        (str_store_string, s2, "@ Your engineer skill has increased by 1."),
    (try_end),
    (unlock_achievement, 37),
    (try_begin),
        (eq, "$g_infinite_camping", 0),
        (dialog_box, "@You have finished reading {s1}.{s2}", "@Book Read"),
    (try_end),
    (assign, "$g_player_reading_book", 0),

]),

(12.000000,
[
    (try_for_parties, ":var_0"),
        (party_slot_eq, ":var_0", slot_party_type, 17),
        (store_distance_to_party_from_party, ":var_1", ":var_0", "p_main_party"),
        (try_begin),
            (gt, ":var_1", 30),
            (remove_party, ":var_0"),
            (try_begin),
                (check_quest_active, "qst_move_cattle_herd"),
                (neg|check_quest_concluded, "qst_move_cattle_herd"),
                (quest_slot_eq, "qst_move_cattle_herd", 8, ":var_0"),
                (call_script, "script_fail_quest", "qst_move_cattle_herd"),
            (try_end),
        (else_try),
            (gt, ":var_1", 10),
            (party_set_slot, ":var_0", slot_town_lord, 0),
            (party_set_ai_behavior, ":var_0", 0),
        (try_end),
    (try_end),

]),

(168.000000,
[
    (try_for_range, ":var_0", "p_village_1", "p_salt_mine"),
        (party_slot_eq, ":var_0", slot_town_lord, "trp_player"),
        (party_slot_eq, ":var_0", 254, 1),
        (party_get_slot, ":var_1", ":var_0", slot_center_player_relation),
        (val_add, ":var_1", 1),
        (val_min, ":var_1", 100),
        (party_set_slot, ":var_0", slot_center_player_relation, ":var_1"),
    (try_end),

]),

(24.000000,
[
    (try_begin),
        (quest_slot_eq, "qst_order_grandmaster", 11, 6),
        (gt, "$order_stronghold_upgrade_days", 0),
        (val_sub, "$order_stronghold_upgrade_days", 1),
        (eq, "$order_stronghold_upgrade_days", 0),
        (party_set_slot, "p_snake_stronghold", slot_town_center, "scn_order_stronghold_exterior"),
        (party_set_slot, "p_snake_stronghold", slot_town_castle, "scn_castle_6_interior"),
        (display_message, "@Your Order Stronghold has been fully rebuilt!"),
        (play_sound, "snd_bellchant"),
    (try_end),
    (try_begin),
        (gt, "$order_blacksmith_days", 0),
        (val_sub, "$order_blacksmith_days", 1),
        (eq, "$order_blacksmith_days", 0),
        (assign, "$order_blacksmith_days", -1),
        (display_message, "@The Order blacksmith sends a message that your armor is ready!"),
        (play_sound, "snd_bellchant"),
    (try_end),
    (try_for_range, ":var_0", 0, "qst_quests_end"),
        (try_begin),
            (check_quest_active, ":var_0"),
            (try_begin),
                (neg|check_quest_concluded, ":var_0"),
                (quest_slot_ge, ":var_0", 23, 1),
                (quest_get_slot, ":var_1", ":var_0", 23),
                (val_sub, ":var_1", 1),
                (try_begin),
                    (eq, ":var_1", 0),
                    (try_begin),
                        (eq, ":var_0", "qst_order_bounty"),
                        (quest_get_slot, ":var_2", "qst_order_bounty", 10),
                        (try_begin),
                            (quest_slot_ge, "qst_order_bounty", 17, ":var_2"),
                            (call_script, "script_succeed_quest", "qst_order_bounty"),
                        (else_try),
                            (call_script, "script_fail_quest", "qst_order_bounty"),
                        (try_end),
                    (else_try),
                        (eq, ":var_0", "qst_order_tournament"),
                        (call_script, "script_fail_quest", "qst_order_tournament"),
                        (quest_get_slot, ":var_3", "qst_order_tournament", 1),
                        (party_set_slot, ":var_3", slot_town_has_tournament, 0),
                    (else_try),
                        (eq, ":var_0", "qst_order_challenge"),
                        (call_script, "script_fail_quest", "qst_order_challenge"),
                    (else_try),
                        (eq, ":var_0", "qst_order_rivalry"),
                        (call_script, "script_fail_quest", "qst_order_rivalry"),
                    (else_try),
                        (call_script, "script_abort_quest", ":var_0", 1),
                    (try_end),
                (else_try),
                    (quest_set_slot, ":var_0", 23, ":var_1"),
                    (assign, reg0, ":var_1"),
                    (add_quest_note_from_sreg, ":var_0", 7, "@You have {reg0} days to finish this quest.", 0),
                (try_end),
            (try_end),
        (else_try),
            (quest_slot_ge, ":var_0", 25, 1),
            (quest_get_slot, ":var_4", ":var_0", 25),
            (val_sub, ":var_4", 1),
            (quest_set_slot, ":var_0", 25, ":var_4"),
        (try_end),
    (try_end),

]),

(2.000000,
[
    (eq, "$g_infinite_camping", 0),
    (is_between, "$players_kingdom", "fac_player_supporters_faction", "fac_kingdoms_end"),
    (eq, "$g_player_is_captive", 0),
    (neg|check_quest_active, "qst_wed_betrothed"),
    (try_begin),
        (check_quest_active, "qst_report_to_army"),
        (faction_slot_eq, "$players_kingdom", slot_faction_marshall, -1),
        (call_script, "script_abort_quest", "qst_report_to_army", 0),
    (try_end),
    (faction_get_slot, ":var_0", "$players_kingdom", slot_faction_ai_object),
    (neg|faction_slot_eq, "$players_kingdom", slot_faction_ai_state, 0),
    (neg|faction_slot_eq, "$players_kingdom", slot_faction_ai_state, 6),
    (assign, ":var_1", 1),
    (try_begin),
        (this_or_next|faction_slot_eq, "$players_kingdom", slot_faction_ai_state, 5),
        (this_or_next|faction_slot_eq, "$players_kingdom", slot_faction_ai_state, 2),
        (faction_slot_eq, "$players_kingdom", slot_faction_ai_state, 3),
        (neg|is_between, ":var_0", "p_town_1", "p_village_1"),
        (assign, ":var_1", 0),
    (try_end),
    (eq, ":var_1", 1),
    (assign, ":var_2", 0),
    (try_for_range, ":var_3", "fac_player_supporters_faction", "fac_kingdoms_end"),
        (neg|eq, ":var_3", "$players_kingdom"),
        (store_relation, ":var_4", ":var_3", "$players_kingdom"),
        (neg|ge, ":var_4", 0),
        (assign, ":var_2", 1),
    (try_end),
    (eq, ":var_2", 1),
    (neg|check_quest_active, "qst_report_to_army"),
    (neg|check_quest_active, "qst_follow_army"),
    (neg|quest_slot_ge, "qst_report_to_army", 25, 1),
    (faction_get_slot, ":var_5", "$players_kingdom", slot_faction_marshall),
    (gt, ":var_5", 0),
    (troop_get_slot, ":var_6", ":var_5", slot_troop_leaded_party),
    (gt, ":var_6", 0),
    (party_is_active, ":var_6"),
    (store_distance_to_party_from_party, ":var_7", ":var_6", "p_main_party"),
    (neg|gt, ":var_7", 96),
    (assign, ":var_8", 1),
    (try_for_range, ":var_9", "qst_deliver_message", "qst_follow_army"),
        (check_quest_active, ":var_9"),
        (quest_slot_eq, ":var_9", 6, ":var_5"),
        (assign, ":var_8", 0),
    (try_end),
    (eq, ":var_8", 1),
    (try_for_range, ":var_9", "qst_destroy_bandit_lair", "qst_ghost_lady"),
        (check_quest_active, ":var_9"),
        (quest_slot_eq, ":var_9", 6, ":var_5"),
        (assign, ":var_8", 0),
    (try_end),
    (eq, ":var_8", 1),
    (try_for_range, ":var_9", "qst_deliver_cattle_to_army", "qst_rescue_lord_by_replace"),
        (check_quest_active, ":var_9"),
        (assign, ":var_8", 0),
    (try_end),
    (eq, ":var_8", 1),
    (store_character_level, ":var_10", "trp_player"),
    (ge, ":var_10", 8),
    (assign, ":var_11", 2),
    (try_for_range, ":var_12", "p_town_1", "p_salt_mine"),
        (party_slot_eq, ":var_12", slot_town_lord, "trp_player"),
        (try_begin),
            (party_slot_eq, ":var_12", slot_party_type, 3),
            (val_add, ":var_11", 3),
        (else_try),
            (party_slot_eq, ":var_12", slot_party_type, 2),
            (val_add, ":var_11", 1),
        (else_try),
            (val_add, ":var_11", 1),
        (try_end),
    (try_end),
    (val_mul, ":var_11", 4),
    (val_min, ":var_11", 60),
    (quest_set_slot, "qst_report_to_army", 6, ":var_5"),
    (quest_set_slot, "qst_report_to_army", 2, ":var_5"),
    (quest_set_slot, "qst_report_to_army", 10, ":var_11"),
    (quest_set_slot, "qst_report_to_army", 23, 4),
    (quest_set_slot, "qst_report_to_army", 24, 22),
    (jump_to_menu, "mnu_kingdom_army_quest_report_to_army"),

]),

(3.000000,
[
    (assign, "$g_random_army_quest", -1),
    (check_quest_active, "qst_follow_army", 1),
    (is_between, "$players_kingdom", "fac_player_supporters_faction", "fac_kingdoms_end"),
    (neg|faction_slot_eq, "$players_kingdom", slot_faction_ai_state, 0),
    (faction_get_slot, ":var_0", "$players_kingdom", slot_faction_marshall),
    (neg|eq, ":var_0", "trp_player"),
    (gt, ":var_0", 0),
    (troop_get_slot, ":var_1", ":var_0", slot_troop_leaded_party),
    (gt, ":var_1", 0),
    (party_is_active, ":var_1"),
    (store_distance_to_party_from_party, ":var_2", ":var_1", "p_main_party"),
    (try_begin),
        (neg|ge, ":var_2", 15),
        (assign, "$g_player_follow_army_warnings", 0),
        (store_current_hours, ":var_3"),
        (faction_get_slot, ":var_4", "$players_kingdom", slot_faction_ai_last_offensive_time),
        (store_sub, ":var_5", ":var_3", ":var_4"),
        (assign, ":var_6", -1),
        (try_begin),
            (store_random_in_range, ":var_7", 0, 100),
            (neg|ge, ":var_7", 30),
            (troop_slot_eq, ":var_0", slot_troop_does_not_give_quest, 0),
            (try_for_range, ":var_8", 0, 20),
                (eq, ":var_6", -1),
                (store_random_in_range, ":var_9", "qst_deliver_cattle_to_army", "qst_rescue_lord_by_replace"),
                (neg|quest_slot_ge, ":var_9", 25, 1),
                (try_begin),
                    (eq, ":var_9", "qst_deliver_cattle_to_army"),
                    (try_begin),
                        (faction_slot_eq, "$players_kingdom", slot_faction_ai_state, 2),
                        (gt, ":var_5", 120),
                        (store_random_in_range, ":var_10", 5, 10),
                        (assign, ":var_6", "qst_deliver_cattle_to_army"),
                        (quest_set_slot, ":var_6", 10, ":var_10"),
                        (quest_set_slot, ":var_6", 23, 10),
                        (quest_set_slot, ":var_6", 24, 30),
                    (try_end),
                (else_try),
                    (eq, ":var_9", "qst_join_siege_with_army"),
                    (eq, 1, 0),
                    (try_begin),
                        (faction_slot_eq, "$players_kingdom", slot_faction_ai_state, 2),
                        (faction_get_slot, ":var_11", "$players_kingdom", slot_faction_ai_object),
                        (is_between, ":var_11", "p_town_1", "p_village_1"),
                        (party_get_battle_opponent, ":var_12", ":var_1"),
                        (eq, ":var_12", ":var_11"),
                        (assign, ":var_6", ":var_9"),
                        (quest_set_slot, ":var_6", 1, ":var_11"),
                        (quest_set_slot, ":var_6", 23, 2),
                        (quest_set_slot, ":var_6", 24, 15),
                    (try_end),
                (else_try),
                    (eq, ":var_9", "qst_scout_waypoints"),
                    (try_begin),
                        (assign, ":var_13", 100),
                        (assign, "$qst_scout_waypoints_wp_1", -1),
                        (assign, "$qst_scout_waypoints_wp_2", -1),
                        (assign, "$qst_scout_waypoints_wp_3", -1),
                        (assign, ":var_14", 0),
                        (try_for_range, ":var_8", 0, ":var_13"),
                            (try_begin),
                                (neg|ge, "$qst_scout_waypoints_wp_1", 0),
                                (call_script, "script_cf_get_random_enemy_center_within_range", ":var_1", 50),
                                (assign, "$qst_scout_waypoints_wp_1", reg0),
                            (try_end),
                            (try_begin),
                                (neg|ge, "$qst_scout_waypoints_wp_2", 0),
                                (call_script, "script_cf_get_random_enemy_center_within_range", ":var_1", 50),
                                (neg|eq, "$qst_scout_waypoints_wp_1", reg0),
                                (assign, "$qst_scout_waypoints_wp_2", reg0),
                            (try_end),
                            (try_begin),
                                (neg|ge, "$qst_scout_waypoints_wp_3", 0),
                                (call_script, "script_cf_get_random_enemy_center_within_range", ":var_1", 50),
                                (neg|eq, "$qst_scout_waypoints_wp_1", reg0),
                                (neg|eq, "$qst_scout_waypoints_wp_2", reg0),
                                (assign, "$qst_scout_waypoints_wp_3", reg0),
                            (try_end),
                            (neg|eq, "$qst_scout_waypoints_wp_1", "$qst_scout_waypoints_wp_2"),
                            (neg|eq, "$qst_scout_waypoints_wp_1", "$qst_scout_waypoints_wp_2"),
                            (neg|eq, "$qst_scout_waypoints_wp_2", "$qst_scout_waypoints_wp_3"),
                            (ge, "$qst_scout_waypoints_wp_1", 0),
                            (ge, "$qst_scout_waypoints_wp_2", 0),
                            (ge, "$qst_scout_waypoints_wp_3", 0),
                            (assign, ":var_13", 0),
                            (assign, ":var_14", 1),
                        (try_end),
                        (eq, ":var_14", 1),
                        (assign, "$qst_scout_waypoints_wp_1_visited", 0),
                        (assign, "$qst_scout_waypoints_wp_2_visited", 0),
                        (assign, "$qst_scout_waypoints_wp_3_visited", 0),
                        (assign, ":var_6", "qst_scout_waypoints"),
                        (quest_set_slot, ":var_6", 23, 7),
                        (quest_set_slot, ":var_6", 24, 25),
                    (try_end),
                (try_end),
            (try_end),
            (try_begin),
                (neg|eq, ":var_6", -1),
                (quest_set_slot, ":var_6", 11, 0),
                (quest_set_slot, ":var_6", 6, ":var_0"),
                (try_begin),
                    (eq, ":var_6", "qst_join_siege_with_army"),
                    (jump_to_menu, "mnu_kingdom_army_quest_join_siege_order"),
                (else_try),
                    (assign, "$g_random_army_quest", ":var_6"),
                    (quest_set_slot, "$g_random_army_quest", 6, ":var_0"),
                    (jump_to_menu, "mnu_kingdom_army_quest_messenger"),
                (try_end),
            (try_end),
        (try_end),
    (else_try),
        (val_add, "$g_player_follow_army_warnings", 1),
        (try_begin),
            (neg|ge, "$g_player_follow_army_warnings", 15),
            (try_begin),
                (store_mod, ":var_15", "$g_player_follow_army_warnings", 3),
                (eq, ":var_15", 0),
                (str_store_troop_name_link, s1, ":var_0"),
                (try_begin),
                    (neg|ge, "$g_player_follow_army_warnings", 8),
                (else_try),
                    (display_message, "str_marshal_warning"),
                (try_end),
            (try_end),
        (else_try),
            (jump_to_menu, "mnu_kingdom_army_follow_failed"),
        (try_end),
    (try_end),

]),

(0.500000,
[
    (check_quest_active, "qst_move_cattle_herd"),
    (neg|check_quest_concluded, "qst_move_cattle_herd"),
    (quest_get_slot, ":var_0", "qst_move_cattle_herd", 8),
    (quest_get_slot, ":var_1", "qst_move_cattle_herd", 1),
    (store_distance_to_party_from_party, ":var_2", ":var_0", ":var_1"),
    (neg|ge, ":var_2", 3),
    (remove_party, ":var_0"),
    (call_script, "script_succeed_quest", "qst_move_cattle_herd"),

]),

(2.000000,
[
    (try_for_range, ":var_0", "trp_npc_adonja", "trp_knight_1_1_wife"),
        (troop_slot_eq, ":var_0", slot_troop_occupation, 2),
        (troop_get_slot, ":var_1", ":var_0", slot_troop_leaded_party),
        (ge, ":var_1", 1),
        (party_is_active, ":var_1"),
        (party_slot_eq, ":var_1", slot_party_following_player, 1),
        (store_current_hours, ":var_2"),
        (neg|party_slot_ge, ":var_1", slot_party_follow_player_until_time, ":var_2"),
        (party_set_slot, ":var_1", slot_party_commander_party, -1),
        (party_set_slot, ":var_1", slot_party_following_player, 0),
        (assign, ":var_3", 200),
        (store_add, ":var_4", ":var_2", ":var_3"),
        (party_set_slot, ":var_1", slot_party_dont_follow_player_until_time, ":var_4"),
    (try_end),

]),

(0.500000,
[
    (try_begin),
        (check_quest_active, "qst_deliver_cattle"),
        (neg|check_quest_succeeded, "qst_deliver_cattle"),
        (quest_get_slot, ":var_0", "qst_deliver_cattle", 1),
        (quest_get_slot, ":var_1", "qst_deliver_cattle", 10),
        (quest_get_slot, ":var_2", "qst_deliver_cattle", 11),
        (store_sub, ":var_3", ":var_1", ":var_2"),
        (call_script, "script_remove_cattles_if_herd_is_close_to_party", ":var_0", ":var_3"),
        (val_add, ":var_2", reg0),
        (quest_set_slot, "qst_deliver_cattle", 11, ":var_2"),
        (neg|gt, ":var_1", ":var_2"),
        (call_script, "script_succeed_quest", "qst_deliver_cattle"),
    (try_end),
    (try_begin),
        (check_quest_active, "qst_deliver_cattle_to_army"),
        (neg|check_quest_succeeded, "qst_deliver_cattle_to_army"),
        (quest_get_slot, ":var_4", "qst_deliver_cattle_to_army", 6),
        (troop_get_slot, ":var_5", ":var_4", slot_troop_leaded_party),
        (try_begin),
            (gt, ":var_5", 0),
            (quest_get_slot, ":var_1", "qst_deliver_cattle_to_army", 10),
            (quest_get_slot, ":var_2", "qst_deliver_cattle_to_army", 11),
            (store_sub, ":var_3", ":var_1", ":var_2"),
            (call_script, "script_remove_cattles_if_herd_is_close_to_party", ":var_5", ":var_3"),
            (val_add, ":var_2", reg0),
            (quest_set_slot, "qst_deliver_cattle_to_army", 11, ":var_2"),
            (try_begin),
                (neg|gt, ":var_1", ":var_2"),
                (call_script, "script_succeed_quest", "qst_deliver_cattle_to_army"),
            (try_end),
        (else_try),
            (call_script, "script_abort_quest", "qst_deliver_cattle_to_army", 0),
        (try_end),
    (try_end),

]),

(1.000000,
[
    (neg|map_free),
    (check_quest_active, "qst_train_peasants_against_bandits"),
    (neg|check_quest_concluded, "qst_train_peasants_against_bandits"),
    (eq, "$qst_train_peasants_against_bandits_currently_training", 1),
    (val_add, "$qst_train_peasants_against_bandits_num_hours_trained", 1),
    (call_script, "script_get_max_skill_of_player_party", "skl_trainer"),
    (assign, ":var_0", reg0),
    (store_sub, ":var_1", 20, ":var_0"),
    (val_mul, ":var_1", 3),
    (val_div, ":var_1", 5),
    (ge, "$qst_train_peasants_against_bandits_num_hours_trained", ":var_1"),
    (assign, "$qst_train_peasants_against_bandits_num_hours_trained", 0),
    (rest_for_hours, 0, 0, 0),
    (jump_to_menu, "mnu_train_peasants_against_bandits_ready"),

]),

(1.000000,
[
    (check_quest_active, "qst_scout_waypoints"),
    (neg|check_quest_succeeded, "qst_scout_waypoints"),
    (try_begin),
        (eq, "$qst_scout_waypoints_wp_1_visited", 0),
        (store_distance_to_party_from_party, ":var_0", "$qst_scout_waypoints_wp_1", "p_main_party"),
        (neg|gt, ":var_0", 3),
        (assign, "$qst_scout_waypoints_wp_1_visited", 1),
        (str_store_party_name_link, s1, "$qst_scout_waypoints_wp_1"),
        (display_message, "@{s1} is scouted.", 0x66CCFF),
    (try_end),
    (try_begin),
        (eq, "$qst_scout_waypoints_wp_2_visited", 0),
        (store_distance_to_party_from_party, ":var_0", "$qst_scout_waypoints_wp_2", "p_main_party"),
        (neg|gt, ":var_0", 3),
        (assign, "$qst_scout_waypoints_wp_2_visited", 1),
        (str_store_party_name_link, s1, "$qst_scout_waypoints_wp_2"),
        (display_message, "@{s1} is scouted.", 0x66CCFF),
    (try_end),
    (try_begin),
        (eq, "$qst_scout_waypoints_wp_3_visited", 0),
        (store_distance_to_party_from_party, ":var_0", "$qst_scout_waypoints_wp_3", "p_main_party"),
        (neg|gt, ":var_0", 3),
        (assign, "$qst_scout_waypoints_wp_3_visited", 1),
        (str_store_party_name_link, s1, "$qst_scout_waypoints_wp_3"),
        (display_message, "@{s1} is scouted.", 0x66CCFF),
    (try_end),
    (eq, "$qst_scout_waypoints_wp_1_visited", 1),
    (eq, "$qst_scout_waypoints_wp_2_visited", 1),
    (eq, "$qst_scout_waypoints_wp_3_visited", 1),
    (call_script, "script_succeed_quest", "qst_scout_waypoints"),

]),

(3.000000,
[
    (neg|map_free),
    (check_quest_active, "qst_kill_local_merchant"),
    (quest_slot_eq, "qst_kill_local_merchant", 11, 0),
    (quest_set_slot, "qst_kill_local_merchant", 11, 1),
    (rest_for_hours, 0, 0, 0),
    (assign, "$auto_enter_town", "$qst_kill_local_merchant_center"),
    (assign, "$quest_auto_menu", "mnu_kill_local_merchant_begin"),

]),

(1.000000,
[
    (neg|map_free),
    (check_quest_active, "qst_collect_taxes"),
    (eq, "$g_player_is_captive", 0),
    (eq, "$qst_collect_taxes_currently_collecting", 1),
    (quest_get_slot, ":var_0", "qst_collect_taxes", 11),
    (this_or_next|eq, ":var_0", 1),
    (this_or_next|eq, ":var_0", 2),
    (eq, ":var_0", 3),
    (quest_get_slot, ":var_1", "qst_collect_taxes", 10),
    (val_sub, ":var_1", 1),
    (quest_set_slot, "qst_collect_taxes", 10, ":var_1"),
    (call_script, "script_get_max_skill_of_player_party", "skl_trade"),
    (try_begin),
        (neg|ge, ":var_1", 0),
        (assign, ":var_0", 4),
        (quest_set_slot, "qst_collect_taxes", 11, 4),
        (rest_for_hours, 0, 0, 0),
        (jump_to_menu, "mnu_collect_taxes_complete"),
    (else_try),
        (assign, ":var_2", "$qst_collect_taxes_hourly_income"),
        (party_get_slot, ":var_3", "$g_encountered_party", slot_town_prosperity),
        (store_add, ":var_4", 90, ":var_3"),
        (val_mul, ":var_2", ":var_4"),
        (val_div, ":var_2", 240),
        (try_begin),
            (eq, "$qst_collect_taxes_halve_taxes", 1),
            (val_div, ":var_2", 2),
        (try_end),
        (val_max, ":var_2", 2),
        (store_random_in_range, ":var_5", 1, ":var_2"),
        (quest_get_slot, ":var_6", "qst_collect_taxes", 22),
        (val_add, ":var_6", ":var_5"),
        (quest_set_slot, "qst_collect_taxes", 22, ":var_6"),
        (call_script, "script_troop_add_gold", "trp_player", ":var_5"),
    (try_end),
    (try_begin),
        (eq, ":var_0", 1),
        (val_sub, "$qst_collect_taxes_menu_counter", 1),
        (neg|gt, "$qst_collect_taxes_menu_counter", 0),
        (quest_set_slot, "qst_collect_taxes", 11, 2),
        (jump_to_menu, "mnu_collect_taxes_revolt_warning"),
    (else_try),
        (eq, ":var_0", 2),
        (val_sub, "$qst_collect_taxes_unrest_counter", 1),
        (neg|gt, "$qst_collect_taxes_unrest_counter", 0),
        (eq, "$qst_collect_taxes_halve_taxes", 0),
        (quest_set_slot, "qst_collect_taxes", 11, 3),
        (store_div, ":var_7", 10000, "$qst_collect_taxes_total_hours"),
        (val_add, ":var_7", 30),
        (store_random_in_range, ":var_8", 0, 1000),
        (try_begin),
            (neg|ge, ":var_8", ":var_7"),
            (jump_to_menu, "mnu_collect_taxes_revolt"),
        (try_end),
    (try_end),

]),

(72.000000,
[
    (gt, "$g_force_peace_faction_1", 0),
    (gt, "$g_force_peace_faction_2", 0),
    (try_begin),
        (store_relation, ":var_0", "$g_force_peace_faction_1", "$g_force_peace_faction_2"),
        (neg|ge, ":var_0", 0),
        (call_script, "script_diplomacy_start_peace_between_kingdoms", "$g_force_peace_faction_1", "$g_force_peace_faction_2", 1),
    (try_end),
    (assign, "$g_force_peace_faction_1", 0),
    (assign, "$g_force_peace_faction_2", 0),

]),

(1.000000,
[
    (str_store_string, s51, "str_no_trigger_noted"),
    (try_begin),
        (gt, "$npc_to_rejoin_party", 0),
        (eq, "$g_infinite_camping", 0),
        (try_begin),
            (neg|main_party_has_troop, "$npc_to_rejoin_party"),
            (neg|eq, "$g_player_is_captive", 1),
            (str_store_string, s51, "str_triggered_by_npc_to_rejoin_party"),
            (assign, "$npc_map_talk_context", 151),
            (assign, "$npc_dialog_partner", 0),
            (start_map_conversation, "$npc_to_rejoin_party", -1),
        (else_try),
            (troop_set_slot, "$npc_to_rejoin_party", slot_troop_mission_object, 8),
            (assign, "$npc_to_rejoin_party", 0),
        (try_end),
    (else_try),
        (gt, "$npc_is_quitting", 0),
        (eq, "$g_infinite_camping", 0),
        (try_begin),
            (main_party_has_troop, "$npc_is_quitting"),
            (neg|eq, "$g_player_is_captive", 1),
            (str_store_string, s51, "str_triggered_by_npc_is_quitting"),
            (assign, "$npc_dialog_partner", 0),
            (start_map_conversation, "$npc_is_quitting", -1),
        (else_try),
            (assign, "$npc_is_quitting", 0),
        (try_end),
    (else_try),
        (gt, "$npc_with_grievance", 0),
        (eq, "$g_infinite_camping", 0),
        (try_begin),
            (main_party_has_troop, "$npc_with_grievance"),
            (neg|eq, "$g_player_is_captive", 1),
            (str_store_string, s51, "str_triggered_by_npc_has_grievance"),
            (assign, "$npc_map_talk_context", 61),
            (assign, "$npc_dialog_partner", 0),
            (start_map_conversation, "$npc_with_grievance", -1),
        (else_try),
            (assign, "$npc_with_grievance", 0),
        (try_end),
    (else_try),
        (gt, "$npc_with_personality_clash", 0),
        (eq, "$g_infinite_camping", 0),
        (troop_get_slot, ":var_0", "$npc_with_personality_clash", slot_troop_personalityclash_object),
        (try_begin),
            (main_party_has_troop, "$npc_with_personality_clash"),
            (main_party_has_troop, ":var_0"),
            (neg|eq, "$g_player_is_captive", 1),
            (assign, "$npc_map_talk_context", 72),
            (str_store_string, s51, "str_triggered_by_npc_has_personality_clash"),
            (assign, "$npc_dialog_partner", 0),
            (start_map_conversation, "$npc_with_personality_clash", -1),
        (else_try),
            (assign, "$npc_with_personality_clash", 0),
        (try_end),
    (else_try),
        (gt, "$npc_with_political_grievance", 0),
        (eq, "$g_infinite_camping", 0),
        (eq, "$disable_npc_complaints", 0),
        (try_begin),
            (main_party_has_troop, "$npc_with_political_grievance"),
            (neg|eq, "$g_player_is_captive", 1),
            (str_store_string, s51, "str_triggered_by_npc_has_political_grievance"),
            (assign, "$npc_map_talk_context", 145),
            (assign, "$npc_dialog_partner", 0),
            (start_map_conversation, "$npc_with_political_grievance", -1),
        (else_try),
            (assign, "$npc_with_political_grievance", 0),
        (try_end),
    (else_try),
        (eq, "$disable_local_histories", 0),
        (neg|eq, "$g_option_companion_dialogs", 0),
        (eq, "$g_infinite_camping", 0),
        (try_for_range, ":var_1", "trp_npc_adonja", "trp_kingdom_1_lord"),
            (main_party_has_troop, ":var_1"),
            (troop_slot_eq, ":var_1", slot_troop_home_speech_delivered, 0),
            (troop_get_slot, ":var_2", ":var_1", slot_troop_home),
            (gt, ":var_2", 0),
            (store_distance_to_party_from_party, ":var_3", ":var_2", "p_main_party"),
            (neg|ge, ":var_3", 7),
            (assign, "$npc_map_talk_context", 60),
            (str_store_string, s51, "str_triggered_by_local_histories"),
            (assign, "$npc_dialog_partner", 0),
            (start_map_conversation, ":var_1", -1),
        (try_end),
    (try_end),
    (try_begin),
        (check_quest_active, "qst_rebel_against_kingdom"),
        (is_between, "$supported_pretender", "trp_kingdom_1_pretender", "trp_knight_1_1_wife"),
        (neg|main_party_has_troop, "$supported_pretender"),
        (neg|troop_slot_eq, "$supported_pretender", slot_troop_occupation, 2),
        (party_add_members, "p_main_party", "$supported_pretender", 1),
    (try_end),
    (try_begin),
        (check_quest_active, "qst_rebel_against_kingdom"),
        (is_between, "$supported_pretender", "trp_kingdom_1_pretender", "trp_knight_1_1_wife"),
        (main_party_has_troop, "$supported_pretender"),
        (neg|faction_slot_eq, "fac_player_supporters_faction", slot_faction_marshall, "trp_player"),
        (call_script, "script_appoint_faction_marshall", "fac_player_supporters_faction", "trp_player"),
    (try_end),

]),

(4.000000,
[
    (try_for_range, ":var_0", "trp_npc_adonja", "trp_knight_1_1_wife"),
        (troop_slot_ge, ":var_0", slot_troop_change_to_faction, 1),
        (store_troop_faction, ":var_1", ":var_0"),
        (troop_get_slot, ":var_2", ":var_0", slot_troop_change_to_faction),
        (troop_get_slot, ":var_3", ":var_0", slot_troop_leaded_party),
        (assign, ":var_4", 0),
        (try_begin),
            (neg|gt, ":var_3", 0),
            (neg|troop_slot_ge, ":var_0", slot_troop_prisoner_of_party, 0),
            (assign, ":var_4", 1),
        (else_try),
            (gt, ":var_3", 0),
            (party_get_attached_to, ":var_5", ":var_3"),
            (try_begin),
                (neg|ge, ":var_5", 0),
                (party_get_cur_town, ":var_5", ":var_3"),
            (try_end),
            (this_or_next|neg|is_between, ":var_5", "p_town_1", "p_salt_mine"),
            (party_slot_eq, ":var_5", slot_town_lord, ":var_0"),
            (assign, ":var_6", "trp_knight_1_1_wife"),
            (try_for_range, ":var_7", "trp_npc_adonja", ":var_6"),
                (troop_slot_eq, ":var_7", slot_troop_occupation, 2),
                (troop_get_slot, ":var_8", ":var_7", slot_troop_leaded_party),
                (party_is_active, ":var_8"),
                (store_faction_of_party, ":var_9", ":var_8"),
                (eq, ":var_9", ":var_1"),
                (store_distance_to_party_from_party, ":var_10", ":var_3", ":var_8"),
                (neg|ge, ":var_10", 4),
                (assign, ":var_6", 0),
            (try_end),
            (neg|eq, ":var_6", 0),
            (assign, ":var_4", 1),
        (try_end),
        (eq, ":var_4", 1),
        (str_store_troop_name, s36, ":var_0"),
        (try_begin),
            (ge, "$cheat_mode", 1),
            (str_store_troop_name, s4, ":var_0"),
            (display_message, "@{!}DEBUG - {s4} faction changed from slot troop change to faction"),
        (try_end),
        (call_script, "script_change_troop_faction", ":var_0", ":var_2"),
        (troop_set_slot, ":var_0", slot_troop_change_to_faction, 0),
        (try_begin),
            (is_between, ":var_2", "fac_player_supporters_faction", "fac_kingdoms_end"),
            (str_store_troop_name_link, s1, ":var_0"),
            (str_store_faction_name_link, s2, ":var_1"),
            (str_store_faction_name_link, s3, ":var_2"),
            (display_message, "@{s36} has switched from the {s2} to the {s3} and is now known as {s1}.", 0x66CCFF),
            (try_begin),
                (eq, ":var_1", "$players_kingdom"),
                (call_script, "script_add_notification_menu", "mnu_notification_troop_left_players_faction", ":var_0", ":var_2"),
            (else_try),
                (eq, ":var_2", "$players_kingdom"),
                (call_script, "script_add_notification_menu", "mnu_notification_troop_joined_players_faction", ":var_0", ":var_1"),
            (try_end),
        (try_end),
    (try_end),

]),

(1.000000,
[
    (eq, "$cheat_mode", 1),
    (try_for_range, ":var_0", "p_town_1", "p_salt_mine"),
        (party_get_battle_opponent, ":var_1", ":var_0"),
        (try_begin),
            (gt, ":var_1", 0),
            (str_store_party_name, s2, ":var_0"),
            (str_store_party_name, s3, ":var_1"),
            (display_message, "@{!}DEBUG : {s2} is besieged by {s3}"),
        (try_end),
    (try_end),

]),

(1.000000,
[
    (store_current_day, ":var_0"),
    (gt, ":var_0", "$g_last_report_control_day"),
    (store_time_of_day, ":var_1"),
    (ge, ":var_1", 18),
    (store_random_in_range, ":var_2", 0, 4),
    (this_or_next|ge, ":var_1", 22),
    (eq, ":var_2", 0),
    (assign, "$g_last_report_control_day", ":var_0"),
    (store_troop_gold, ":var_3", "trp_player"),
    (try_begin),
        (neg|ge, ":var_3", 0),
        (store_sub, ":var_4", 0, ":var_3"),
        (troop_add_gold, "trp_player", ":var_4"),
    (try_end),
    (party_get_morale, ":var_5", "p_main_party"),
    (try_begin),
        (str_store_string, s1, "str_party_morale_is_low"),
        (str_clear, s2),
        (party_get_num_companion_stacks, ":var_6", "p_main_party"),
        (assign, ":var_7", 0),
        (try_for_range_backwards, ":var_8", 0, ":var_6"),
            (party_stack_get_troop_id, ":var_9", "p_main_party", ":var_8"),
            (neg|troop_is_hero, ":var_9"),
            (party_stack_get_size, ":var_10", "p_main_party", ":var_8"),
            (store_troop_faction, ":var_11", ":var_9"),
            (assign, ":var_12", ":var_5"),
            (try_begin),
                (ge, ":var_11", "fac_kingdom_1"),
                (neg|ge, ":var_11", "fac_kingdoms_end"),
                (faction_get_slot, ":var_13", ":var_11", slot_faction_morale_of_player_troops),
                (val_div, ":var_13", 100),
                (val_add, ":var_12", ":var_13"),
            (try_end),
            (neg|ge, ":var_12", 32),
            (store_sub, ":var_14", 36, ":var_12"),
            (val_div, ":var_14", 4),
            (assign, ":var_15", 0),
            (try_for_range, ":var_16", 0, ":var_10"),
                (store_random_in_range, ":var_2", 0, 100),
                (neg|ge, ":var_2", ":var_14"),
                (val_add, ":var_15", 1),
                (remove_member_from_party, ":var_9", "p_main_party"),
            (try_end),
            (try_begin),
                (ge, ":var_15", 1),
                (str_store_troop_name, s2, ":var_9"),
                (assign, reg0, ":var_15"),
                (try_begin),
                    (ge, ":var_7", 1),
                    (str_store_string, s1, "str_s1_reg0_s2"),
                (else_try),
                    (str_store_string, s3, 1),
                    (str_store_string, s1, "str_s3_reg0_s2"),
                (try_end),
                (val_add, ":var_7", ":var_15"),
            (try_end),
        (try_end),
        (try_begin),
            (ge, ":var_7", 1),
            (try_begin),
                (ge, ":var_7", 2),
                (str_store_string, s2, "str_have_deserted_the_party"),
            (else_try),
                (str_store_string, s2, "str_has_deserted_the_party"),
            (try_end),
            (str_store_string, s1, "str_s1_s2"),
            (eq, "$g_infinite_camping", 0),
            (dialog_box, 1, "str_weekly_report"),
        (try_end),
    (try_end),

]),

(1.000000,
[
    (call_script, "script_calculate_castle_prosperities_by_using_its_villages"),
    (store_add, ":var_0", "fac_kingdom_5", 1),
    (try_for_range, ":var_1", "fac_kingdom_1", ":var_0"),
        (try_for_range, ":var_2", "fac_kingdom_1", ":var_0"),
            (store_relation, ":var_3", ":var_1", ":var_2"),
            (str_store_faction_name, s7, ":var_1"),
            (str_store_faction_name, s8, ":var_2"),
            (neg|eq, ":var_1", ":var_2"),
            (assign, reg1, ":var_3"),
        (try_end),
    (try_end),

]),

(1.000000,
[
    (try_begin),
        (eq, "$g_player_is_captive", 1),
        (neg|party_is_active, "$capturer_party"),
        (rest_for_hours, 0, 0, 0),
    (try_end),
    (assign, ":var_0", "$next_center_will_be_fired"),
    (party_get_slot, ":var_1", ":var_0", slot_village_smoke_added),
    (eq, ":var_1", 0),
    (try_begin),
        (party_get_slot, ":var_2", ":var_0", slot_village_bound_center),
        (party_get_slot, ":var_3", ":var_2", slot_town_last_nearby_fire_time),
        (store_current_hours, ":var_4"),
        (try_begin),
            (eq, "$cheat_mode", 1),
            (is_between, ":var_0", "p_town_1", "p_salt_mine"),
            (is_between, ":var_2", "p_town_1", "p_salt_mine"),
            (str_store_party_name, s4, ":var_0"),
            (str_store_party_name, s5, ":var_2"),
            (store_current_hours, reg3),
            (party_get_slot, reg4, ":var_2", slot_town_last_nearby_fire_time),
            (display_message, "@{!}DEBUG - Checking fire at {s4} for {s5} - current time {reg3}, last nearby fire {reg4}"),
        (try_end),
        (eq, ":var_4", ":var_3"),
        (party_add_particle_system, ":var_0", "psys_map_village_fire"),
        (party_add_particle_system, ":var_0", "psys_map_village_fire_smoke"),
    (else_try),
        (store_add, ":var_5", ":var_3", 4),
        (eq, ":var_5", ":var_4"),
        (party_clear_particle_systems, ":var_0"),
    (try_end),

]),

(24.000000,
[
    (val_sub, "$g_dont_give_fief_to_player_days", 1),
    (val_max, "$g_dont_give_fief_to_player_days", -1),
    (val_sub, "$g_dont_give_marshalship_to_player_days", 1),
    (val_max, "$g_dont_give_marshalship_to_player_days", -1),
    (try_begin),
        (check_quest_active, "qst_formal_marriage_proposal"),
        (check_quest_failed, "qst_formal_marriage_proposal"),
        (call_script, "script_end_quest", "qst_formal_marriage_proposal"),
    (try_end),
    (try_begin),
        (check_quest_active, "qst_lend_companion"),
        (quest_get_slot, ":var_0", "qst_lend_companion", 6),
        (store_troop_faction, ":var_1", ":var_0"),
        (store_relation, ":var_2", ":var_1", "$players_kingdom"),
        (this_or_next|neg|ge, ":var_2", 0),
        (neg|is_between, ":var_1", "fac_player_supporters_faction", "fac_kingdoms_end"),
        (call_script, "script_abort_quest", "qst_lend_companion", 0),
    (try_end),
    (try_begin),
        (is_between, "$players_kingdom", "fac_player_supporters_faction", "fac_kingdoms_end"),
        (neg|eq, "$players_kingdom", "fac_player_supporters_faction"),
        (faction_slot_eq, "$players_kingdom", slot_faction_marshall, "trp_player"),
        (val_add, "$g_player_days_as_marshal", 1),
    (else_try),
        (assign, "$g_player_days_as_marshal", 0),
    (try_end),
    (try_for_range, ":var_3", "p_town_1", "p_castle_1"),
        (party_get_slot, ":var_4", ":var_3", slot_center_player_enterprise_consumption_order),
        (ge, ":var_4", 1),
        (val_sub, ":var_4", 1),
        (party_set_slot, ":var_3", slot_center_player_enterprise_consumption_order, ":var_4"),
    (try_end),

]),

(24.000000,
[

]),

(24.000000,
[

]),

(24.000000,
[

]),

(24.000000,
[

]),

(24.000000,
[

]),

(24.000000,
[

]),

(24.000000,
[

]),

(24.000000,
[

]),

(24.000000,
[

]),

(24.000000,
[

]),

(1.000000,
[
    (neg|map_free),
    (eq, "$g_player_is_captive", 0),
    (gt, "$pop_train_steward_hours", 0),
    (val_sub, "$pop_train_steward_hours", 1),
    (try_begin),
        (eq, "$pop_train_steward_hours", 0),
        (rest_for_hours, 0, 0, 0),
        (jump_to_menu, "mnu_steward_training_complete"),
    (try_end),

]),

(36.000000,
[
    (try_begin),
        (eq, "$astraea_aid_snd", 0),
        (store_random_in_range, ":var_0", 0, 50),
        (try_begin),
            (neg|ge, ":var_0", 2),
            (call_script, "script_get_closest_center", "p_main_party"),
            (call_script, "script_get_culture_with_party_faction_for_music", reg0),
            (eq, reg0, 8),
            (assign, "$astraea_aid_snd", 1),
            (play_sound, "snd_astraea_aid_when_can"),
            (display_message, "@A god's voice booms across the sky:  I am Astraea, Goddess of Justice.  Fight to defend it and I will aid you when and where I can.", 0x30FFC8),
        (try_end),
    (try_end),
    (try_begin),
        (eq, "$wrath_of_indar", 0),
        (store_random_in_range, ":var_0", 0, 10),
        (try_begin),
            (eq, ":var_0", 1),
            (store_num_parties_destroyed_by_player, ":var_1", "pt_jatu_k_juda"),
            (store_num_parties_destroyed_by_player, ":var_2", "pt_jatu_zulkar"),
            (this_or_next|gt, ":var_1", 0),
            (gt, ":var_2", 0),
            (assign, "$wrath_of_indar", 1),
            (play_sound, "snd_beware_wrath_of_indar"),
            (display_message, "@A god's voice booms across the sky:  You battle and defeat my Jatu.  Beware the wrath of Indar.", 0x30FFC8),
        (try_end),
    (try_end),
    (try_begin),
        (neg|faction_slot_eq, "fac_kingdom_5", slot_faction_state, 0),
        (eq, "$damia_command", 0),
        (store_random_in_range, ":var_0", 0, 3),
        (try_begin),
            (eq, ":var_0", 1),
            (assign, "$damia_command", 1),
            (play_sound, "snd_damia_provideo_drive_out_snakes"),
            (display_message, "@A god's voice booms across the sky:  I command you to drive from my lands these foul Serpent Cultists who defile it, in the Name of Damia Provideo.", 0x30FFC8),
        (try_end),
    (try_end),
    (try_begin),
        (eq, "$claws_of_vejovis", 0),
        (try_begin),
            (store_num_parties_destroyed_by_player, ":var_1", "pt_mystmountain_army"),
            (gt, ":var_1", 0),
            (assign, "$claws_of_vejovis", 1),
            (play_sound, "snd_die_vejovis"),
            (display_message, "@A god's voice booms across the sky:  You will cease fighting my children of the Mystmountains or die in the claws of Vejovis.", 0x30FFC8),
        (try_end),
    (try_end),
    (try_begin),
        (eq, "$eunomia_warning", 0),
        (neg|faction_slot_eq, "fac_kingdom_1", slot_faction_state, 0),
        (store_random_in_range, ":var_0", 0, 3),
        (try_begin),
            (eq, ":var_0", 1),
            (assign, "$eunomia_warning", 1),
            (play_sound, "snd_eunomia_stabilitis_warn_of_danger"),
            (display_message, "@A god's voice booms across the sky:  I Eunomia Stabilitis, first in rank amongst the hierarchy of the Pendor Gods, warn you, Chosen One.  You face many dangers ahead.", 0x30FFC8),
        (try_end),
    (try_end),
    (try_begin),
        (eq, "$hafsigla_wrath", 0),
        (try_begin),
            (store_num_parties_destroyed_by_player, ":var_1", "pt_sea_raider_army"),
            (gt, ":var_1", 0),
            (assign, "$hafsigla_wrath", 1),
            (play_sound, "snd_incur_wrath_of_hafsigla"),
            (display_message, "@A god's voice booms across the sky:  End your persecution of my raiding Vanskerries or incur the wrath of HafSigla.", 0x30FFC8),
        (try_end),
    (try_end),
    (try_begin),
        (eq, "$thallo_defend", 0),
        (assign, ":var_3", 0),
        (try_for_range, ":var_4", "p_town_1", "p_village_1"),
            (store_faction_of_party, ":var_5", ":var_4"),
            (eq, ":var_5", "fac_kingdom_4"),
            (val_add, ":var_3", 1),
        (try_end),
        (neg|ge, ":var_3", 3),
        (store_random_in_range, ":var_0", 0, 3),
        (try_begin),
            (eq, ":var_0", 1),
            (assign, "$thallo_defend", 1),
            (play_sound, "snd_thallo_defend_fierdsvain"),
            (display_message, "@A god's voice booms across the sky:  Defend my children of the Fierdsvain that they may farm in peace, in the name of Thallo Ver Shures.", 0x30FFC8),
        (try_end),
    (try_end),
    (try_begin),
        (eq, "$vata_command", 0),
        (assign, ":var_3", 0),
        (try_for_range, ":var_4", "p_town_1", "p_village_1"),
            (store_faction_of_party, ":var_5", ":var_4"),
            (eq, ":var_5", "fac_kingdom_3"),
            (val_add, ":var_3", 1),
        (try_end),
        (neg|ge, ":var_3", 3),
        (store_random_in_range, ":var_0", 0, 3),
        (try_begin),
            (eq, ":var_0", 1),
            (assign, "$vata_command", 1),
            (play_sound, "snd_vata_commands"),
            (display_message, "@A god's voice booms across the sky:  I, Vata, command you in my name to destroy those who threaten my D'Shar.", 0x30FFC8),
        (try_end),
    (try_end),

]),

(24.000000,
[
    (try_begin),
        (eq, "$ullbow", 0),
        (try_begin),
            (store_num_parties_of_template, ":var_0", "pt_wolfbode"),
            (ge, ":var_0", 1),
            (party_template_get_slot, ":var_1", "pt_wolfbode", 7),
            (store_distance_to_party_from_party, ":var_2", ":var_1", "p_main_party"),
            (neg|ge, ":var_2", 30),
            (store_free_inventory_capacity, ":var_3", "trp_player"),
            (try_begin),
                (neg|ge, ":var_3", 1),
                (display_message, "@The God UllrVetr is about to give you a gift, but you must have space for it in your inventory.", 0x30FFC8),
            (else_try),
                (ge, ":var_3", 1),
                (assign, "$ullbow", 1),
                (play_sound, "snd_ullrvetr_manifests_as_bow"),
                (display_message, "@A god's voice booms across the sky:  I, UllrVetr, God of Bowmen, manifest myself to you as this bow.  Use it well in the battle to come.", 0x30FFC8),
                (troop_add_item, "trp_player", "itm_pl_326"),
            (try_end),
        (try_end),
    (else_try),
        (eq, "$ullbow", 1),
        (store_num_parties_of_template, ":var_0", "pt_wolfbode"),
        (eq, ":var_0", 0),
        (assign, "$ullbow", 2),
        (try_begin),
            (player_has_item, "itm_pl_326"),
            (troop_remove_item, "trp_player", "itm_pl_326"),
        (else_try),
            (assign, ":var_4", 0),
            (try_for_range, ":var_5", "trp_npc_adonja", "trp_kingdom_1_lord"),
                (eq, ":var_4", 0),
                (troop_has_item_equipped, ":var_5", "itm_pl_326"),
                (troop_remove_item, ":var_5", "itm_pl_326"),
                (str_store_troop_name, s2, ":var_5"),
                (str_store_item_name, s10, "itm_pl_326"),
                (display_message, "@{s2} loses the {s10}."),
                (assign, ":var_4", 1),
            (try_end),
            (eq, ":var_4", 0),
            (try_for_range, ":var_6", "trp_town_1_seneschal", "trp_town_1_arena_master"),
                (eq, ":var_4", 0),
                (troop_get_inventory_capacity, ":var_7", ":var_6"),
                (try_for_range, ":var_8", 0, ":var_7"),
                    (troop_get_inventory_slot, ":var_9", ":var_6", ":var_8"),
                    (eq, ":var_9", "itm_pl_326"),
                    (troop_remove_item, ":var_6", "itm_pl_326"),
                    (str_store_troop_name, s2, ":var_6"),
                    (str_store_item_name, s10, "itm_pl_326"),
                    (display_message, "@{s2} reports the {s10} is gone missing from the castle chest."),
                    (assign, ":var_4", 1),
                    (assign, ":var_7", 0),
                (try_end),
            (try_end),
            (try_begin),
                (eq, ":var_4", 0),
                (troop_remove_item, "trp_bonus_chest_1", "itm_pl_326"),
                (troop_remove_item, "trp_bonus_chest_2", "itm_pl_326"),
                (troop_remove_item, "trp_bonus_chest_3", "itm_pl_326"),
            (try_end),
        (try_end),
    (try_end),

]),

(24.000000,
[
    (assign, ":var_0", 0),
    (troop_get_slot, ":var_1", "trp_player", slot_troop_renown),
    (try_begin),
        (store_and, ":var_0", "$g_achieve_bitfield", 16384),
        (eq, ":var_0", 0),
        (ge, ":var_1", 7500),
        (val_or, "$g_achieve_bitfield", 16384),
        (val_or, "$g_achieve_bitfield", 8192),
        (val_sub, "$g_achieve_bitfield", 8192),
        (call_script, "script_add_notification_menu", "mnu_achievement_notify", "str_achieve_rnwn_2", 14),
    (else_try),
        (store_and, ":var_0", "$g_achieve_bitfield", 16384),
        (eq, ":var_0", 0),
        (store_and, ":var_0", "$g_achieve_bitfield", 8192),
        (eq, ":var_0", 0),
        (ge, ":var_1", 5000),
        (val_or, "$g_achieve_bitfield", 8192),
        (call_script, "script_add_notification_menu", "mnu_achievement_notify", "str_achieve_rnwn_1", 13),
    (try_end),
    (try_begin),
        (store_and, ":var_0", "$g_achieve_bitfield", 16),
        (eq, ":var_0", 0),
        (ge, "$g_total_victories", 500),
        (val_or, "$g_achieve_bitfield", 16),
        (val_or, "$g_achieve_bitfield", 8),
        (val_sub, "$g_achieve_bitfield", 8),
        (call_script, "script_add_notification_menu", "mnu_achievement_notify", "str_achieve_vic_2", 4),
    (else_try),
        (store_and, ":var_0", "$g_achieve_bitfield", 16),
        (eq, ":var_0", 0),
        (store_and, ":var_0", "$g_achieve_bitfield", 8),
        (eq, ":var_0", 0),
        (ge, "$g_total_victories", 250),
        (val_or, "$g_achieve_bitfield", 8),
        (call_script, "script_add_notification_menu", "mnu_achievement_notify", "str_achieve_vic_1", 3),
    (try_end),
    (get_player_agent_kill_count, ":var_2"),
    (get_player_agent_kill_count, ":var_3", 1),
    (val_add, ":var_2", ":var_3"),
    (try_begin),
        (store_and, ":var_0", "$g_achieve_bitfield", 4),
        (eq, ":var_0", 0),
        (ge, ":var_2", 10000),
        (val_or, "$g_achieve_bitfield", 4),
        (val_or, "$g_achieve_bitfield", 2),
        (val_sub, "$g_achieve_bitfield", 2),
        (call_script, "script_add_notification_menu", "mnu_achievement_notify", "str_achieve_kills_2", 2),
    (else_try),
        (store_and, ":var_0", "$g_achieve_bitfield", 4),
        (eq, ":var_0", 0),
        (store_and, ":var_0", "$g_achieve_bitfield", 2),
        (eq, ":var_0", 0),
        (ge, ":var_2", 5000),
        (val_or, "$g_achieve_bitfield", 2),
        (call_script, "script_add_notification_menu", "mnu_achievement_notify", "str_achieve_kills_1", 1),
    (try_end),
    (try_begin),
        (store_and, ":var_0", "$g_achieve_bitfield", 32768),
        (eq, ":var_0", 0),
        (ge, "$player_honor", 500),
        (val_or, "$g_achieve_bitfield", 32768),
        (call_script, "script_add_notification_menu", "mnu_achievement_notify", "str_achieve_honor", 15),
    (try_end),
    (try_begin),
        (store_and, ":var_0", "$g_achieve_bitfield", 4096),
        (eq, ":var_0", 0),
        (ge, "$g_tournaments_won", 50),
        (val_or, "$g_achieve_bitfield", 4096),
        (val_or, "$g_achieve_bitfield", 2048),
        (val_sub, "$g_achieve_bitfield", 2048),
        (call_script, "script_add_notification_menu", "mnu_achievement_notify", "str_achieve_tour_2", 12),
    (else_try),
        (store_and, ":var_0", "$g_achieve_bitfield", 4096),
        (eq, ":var_0", 0),
        (store_and, ":var_0", "$g_achieve_bitfield", 2048),
        (eq, ":var_0", 0),
        (ge, "$g_tournaments_won", 25),
        (val_or, "$g_achieve_bitfield", 2048),
        (call_script, "script_add_notification_menu", "mnu_achievement_notify", "str_achieve_tour_1", 11),
    (try_end),
    (try_begin),
        (store_and, ":var_0", "$g_achieve_bitfield", 128),
        (eq, ":var_0", 0),
        (assign, ":var_4", 0),
        (store_num_parties_destroyed_by_player, ":var_5", "pt_mystmountain_army"),
        (val_add, ":var_4", ":var_5"),
        (store_num_parties_destroyed_by_player, ":var_5", "pt_wolfbode"),
        (val_add, ":var_4", ":var_5"),
        (ge, ":var_4", 1),
        (val_or, "$g_achieve_bitfield", 128),
        (call_script, "script_add_notification_menu", "mnu_achievement_notify", "str_achieve_mysts", 7),
    (try_end),
    (try_begin),
        (store_and, ":var_0", "$g_achieve_bitfield", 256),
        (eq, ":var_0", 0),
        (assign, ":var_4", 0),
        (store_num_parties_destroyed_by_player, ":var_5", "pt_snake_cult_army"),
        (val_add, ":var_4", ":var_5"),
        (store_num_parties_destroyed_by_player, ":var_5", "pt_dread_legion"),
        (val_add, ":var_4", ":var_5"),
        (ge, ":var_4", 1),
        (val_or, "$g_achieve_bitfield", 256),
        (call_script, "script_add_notification_menu", "mnu_achievement_notify", "str_achieve_snakes", 8),
    (try_end),
    (try_begin),
        (store_and, ":var_0", "$g_achieve_bitfield", 512),
        (eq, ":var_0", 0),
        (assign, ":var_4", 0),
        (store_num_parties_destroyed_by_player, ":var_5", "pt_jatu_army"),
        (val_add, ":var_4", ":var_5"),
        (store_num_parties_destroyed_by_player, ":var_5", "pt_jatu_zulkar"),
        (val_add, ":var_4", ":var_5"),
        (store_num_parties_destroyed_by_player, ":var_5", "pt_jatu_k_juda"),
        (val_add, ":var_4", ":var_5"),
        (ge, ":var_4", 1),
        (val_or, "$g_achieve_bitfield", 512),
        (call_script, "script_add_notification_menu", "mnu_achievement_notify", "str_achieve_jatu", 9),
    (try_end),
    (try_begin),
        (store_and, ":var_0", "$g_achieve_bitfield", 1024),
        (eq, ":var_0", 0),
        (assign, ":var_4", 0),
        (store_num_parties_destroyed_by_player, ":var_5", "pt_heretics_army"),
        (val_add, ":var_4", ":var_5"),
        (store_num_parties_destroyed_by_player, ":var_5", "pt_eyegrim"),
        (val_add, ":var_4", ":var_5"),
        (store_num_parties_destroyed_by_player, ":var_5", "pt_three_seers"),
        (val_add, ":var_4", ":var_5"),
        (ge, ":var_4", 1),
        (val_or, "$g_achieve_bitfield", 1024),
        (call_script, "script_add_notification_menu", "mnu_achievement_notify", "str_achieve_heretics", 10),
    (try_end),
    (assign, ":var_6", 0),
    (try_for_range, ":var_7", "pt_wolfbode", "pt_refugees"),
        (store_num_parties_destroyed_by_player, ":var_5", ":var_7"),
        (val_add, ":var_6", ":var_5"),
    (try_end),
    (try_begin),
        (store_and, ":var_0", "$g_achieve_bitfield", 64),
        (eq, ":var_0", 0),
        (ge, ":var_6", 15),
        (val_or, "$g_achieve_bitfield", 64),
        (val_or, "$g_achieve_bitfield", 32),
        (val_sub, "$g_achieve_bitfield", 32),
        (call_script, "script_add_notification_menu", "mnu_achievement_notify", "str_achieve_heroes_2", 6),
    (else_try),
        (store_and, ":var_0", "$g_achieve_bitfield", 64),
        (eq, ":var_0", 0),
        (store_and, ":var_0", "$g_achieve_bitfield", 32),
        (eq, ":var_0", 0),
        (ge, ":var_6", 7),
        (val_or, "$g_achieve_bitfield", 32),
        (call_script, "script_add_notification_menu", "mnu_achievement_notify", "str_achieve_heroes_1", 5),
    (try_end),
    (try_begin),
        (store_and, ":var_0", "$g_achieve_bitfield", 262144),
        (eq, ":var_0", 0),
        (ge, "$g_improvements_built", 30),
        (val_or, "$g_achieve_bitfield", 262144),
        (call_script, "script_add_notification_menu", "mnu_achievement_notify", "str_achieve_builder", 18),
    (try_end),
    (try_begin),
        (store_and, ":var_0", "$g_achieve_bitfield", 131072),
        (eq, ":var_0", 0),
        (ge, "$g_lords_persuaded", 30),
        (val_or, "$g_achieve_bitfield", 131072),
        (call_script, "script_add_notification_menu", "mnu_achievement_notify", "str_achieve_persuader", 17),
    (try_end),
    (try_begin),
        (store_and, ":var_0", "$g_achieve_bitfield", 524288),
        (eq, ":var_0", 0),
        (store_and, ":var_0", "$g_achieve_bitfield", 1048576),
        (eq, ":var_0", 0),
        (ge, "$g_total_quests_completed", 30),
        (val_or, "$g_achieve_bitfield", 524288),
        (call_script, "script_add_notification_menu", "mnu_achievement_notify", "str_achieve_quests", 19),
    (try_end),
    (try_begin),
        (store_and, ":var_0", "$g_achieve_bitfield", 1048576),
        (eq, ":var_0", 0),
        (store_and, ":var_0", "$g_achieve_bitfield", 524288),
        (eq, ":var_0", 0),
        (ge, "$g_quests_failed", 10),
        (val_or, "$g_achieve_bitfield", 1048576),
        (call_script, "script_add_notification_menu", "mnu_achievement_notify", "str_achieve_fquests", 20),
    (try_end),
    (try_begin),
        (store_and, ":var_0", "$g_achieve_bitfield", 2097152),
        (eq, ":var_0", 0),
        (ge, "$g_total_defeats", 10),
        (troop_get_type, ":var_8", "trp_player"),
        (eq, ":var_8", 0),
        (val_or, "$g_achieve_bitfield", 2097152),
        (call_script, "script_add_notification_menu", "mnu_achievement_notify", "str_achieve_captured", 21),
    (try_end),
    (try_begin),
        (store_and, ":var_0", "$g_achieve_bitfield", 4194304),
        (eq, ":var_0", 0),
        (ge, "$g_caravans_raided", 30),
        (val_or, "$g_achieve_bitfield", 4194304),
        (call_script, "script_add_notification_menu", "mnu_achievement_notify", "str_achieve_caravan", 22),
    (try_end),
    (try_begin),
        (store_and, ":var_0", "$g_achieve_bitfield", 8388608),
        (eq, ":var_0", 0),
        (ge, "$g_villages_raided", 20),
        (val_or, "$g_achieve_bitfield", 8388608),
        (call_script, "script_add_notification_menu", "mnu_achievement_notify", "str_achieve_village", 23),
    (try_end),
    (try_begin),
        (store_and, ":var_0", "$g_achieve_bitfield", 65536),
        (eq, ":var_0", 0),
        (store_and, ":var_0", "$g_achieve_bits_delay_popup", 65536),
        (neg|eq, ":var_0", 0),
        (val_or, "$g_achieve_bitfield", 65536),
        (call_script, "script_add_notification_menu", "mnu_achievement_notify", "str_achieve_king", 16),
    (try_end),
    (try_begin),
        (store_and, ":var_0", "$g_achieve_bitfield", 1),
        (eq, ":var_0", 0),
        (store_and, ":var_0", "$g_achieve_bits_delay_popup", 1),
        (neg|eq, ":var_0", 0),
        (val_or, "$g_achieve_bitfield", 1),
        (call_script, "script_add_notification_menu", "mnu_achievement_notify", "str_achieve_kill_battle", 0),
    (try_end),
    (try_begin),
        (eq, 0, 0),
        (store_and, ":var_0", "$g_achieve_bitfield", 67108864),
        (eq, ":var_0", 0),
        (store_and, ":var_0", "$g_achieve_bits_delay_popup", 16777216),
        (neg|eq, ":var_0", 0),
        (val_sub, "$g_achieve_bits_delay_popup", 16777216),
        (try_begin),
            (store_and, ":var_0", "$g_achieve_bitfield", 16777216),
            (eq, ":var_0", 0),
            (val_or, "$g_achieve_bitfield", 16777216),
            (call_script, "script_add_notification_menu", "mnu_achievement_notify", "str_achieve_cheater_warn_1", -1),
        (else_try),
            (store_and, ":var_0", "$g_achieve_bitfield", 33554432),
            (eq, ":var_0", 0),
            (val_or, "$g_achieve_bitfield", 33554432),
            (call_script, "script_add_notification_menu", "mnu_achievement_notify", "str_achieve_cheater_warn_2", -1),
        (else_try),
            (store_and, ":var_0", "$g_achieve_bitfield", 67108864),
            (eq, ":var_0", 0),
            (val_or, "$g_achieve_bitfield", 67108864),
            (call_script, "script_add_notification_menu", "mnu_achievement_notify", "str_achieve_cheater", 24),
        (try_end),
    (try_end),
    (try_begin),
        (store_and, ":var_0", "$g_achieve_bitfield", 134217728),
        (eq, ":var_0", 0),
        (store_and, ":var_0", "$g_achieve_bits_delay_popup", 134217728),
        (neg|eq, ":var_0", 0),
        (val_or, "$g_achieve_bitfield", 134217728),
        (call_script, "script_add_notification_menu", "mnu_achievement_notify", "str_achieve_gm", 25),
    (try_end),

]),

(24.000000,
[
    (neg|check_quest_active, "qst_ghost_lady"),
    (neg|quest_slot_eq, "qst_ghost_lady", 11, 8),
    (assign, ":var_0", 0),
    (assign, ":var_1", 0),
    (assign, ":var_2", 0),
    (assign, ":var_3", 0),
    (assign, ":var_4", 0),
    (assign, ":var_5", 0),
    (try_begin),
        (gt, "$players_kingdom", 0),
        (assign, ":var_0", "$players_kingdom"),
    (try_end),
    (gt, ":var_0", 0),
    (assign, ":var_6", 0),
    (try_for_range, ":var_7", "p_town_1", "p_castle_1"),
        (store_faction_of_party, ":var_8", ":var_7"),
        (eq, ":var_8", ":var_0"),
        (val_add, ":var_6", 1),
    (try_end),
    (ge, ":var_6", 9),
    (assign, ":var_9", 0),
    (assign, ":var_10", 0),
    (assign, ":var_11", 0),
    (try_for_range, ":var_12", 0, 2),
        (eq, ":var_11", 0),
        (try_begin),
            (eq, ":var_12", 1),
            (store_random_in_range, ":var_13", 0, ":var_9"),
            (val_add, ":var_13", 1),
        (try_end),
        (try_for_range, ":var_14", "trp_npc_adonja", "trp_knight_1_1_wife"),
            (eq, ":var_11", 0),
            (troop_slot_eq, ":var_14", slot_troop_occupation, 2),
            (neg|is_between, ":var_14", "trp_kingdom_1_lord", "trp_knight_1_1"),
            (neg|is_between, ":var_14", "trp_kingdom_1_pretender", "trp_knight_1_1_wife"),
            (troop_get_type, ":var_15", ":var_14"),
            (eq, ":var_15", 0),
            (eq, ":var_1", 0),
            (store_troop_faction, ":var_16", ":var_14"),
            (eq, ":var_0", ":var_16"),
            (troop_get_slot, ":var_17", ":var_14", slot_troop_spouse),
            (eq, ":var_17", -1),
            (neg|troop_slot_eq, "trp_player", slot_troop_spouse, ":var_14"),
            (neg|troop_slot_ge, ":var_14", slot_troop_prisoner_of_party, 0),
            (troop_get_slot, ":var_18", ":var_14", slot_troop_leaded_party),
            (gt, ":var_18", 0),
            (party_is_active, ":var_18"),
            (call_script, "script_troop_get_player_relation", ":var_14"),
            (assign, ":var_19", reg0),
            (try_begin),
                (ge, ":var_19", 50),
                (call_script, "script_get_number_of_hero_centers", ":var_14"),
                (assign, ":var_20", reg0),
                (gt, ":var_20", 0),
                (assign, ":var_21", 0),
                (try_for_range, ":var_22", 0, ":var_20"),
                    (eq, ":var_21", 0),
                    (call_script, "script_troop_get_leaded_center_with_index", ":var_14", ":var_22"),
                    (assign, ":var_23", reg0),
                    (is_between, ":var_23", "p_castle_1", "p_village_1"),
                    (try_begin),
                        (eq, ":var_12", 0),
                        (val_add, ":var_9", 1),
                    (else_try),
                        (val_add, ":var_10", 1),
                        (eq, ":var_13", ":var_10"),
                        (assign, ":var_1", ":var_14"),
                        (assign, ":var_2", ":var_23"),
                        (assign, ":var_11", 1),
                    (try_end),
                    (assign, ":var_21", 1),
                (try_end),
            (try_end),
        (try_end),
        (try_begin),
            (eq, ":var_12", 0),
            (eq, ":var_9", 0),
            (assign, ":var_11", 1),
        (try_end),
    (try_end),
    (gt, ":var_1", 0),
    (assign, ":var_3", "trp_ghost_quest_friendly_lord_mistress"),
    (call_script, "script_cf_faction_get_random_enemy_faction", ":var_0"),
    (assign, ":var_5", reg0),
    (gt, ":var_5", 0),
    (call_script, "script_cf_get_random_lord_except_king_with_faction", ":var_5"),
    (assign, ":var_4", reg0),
    (gt, ":var_4", 0),
    (quest_set_slot, "qst_ghost_lady", 1, ":var_2"),
    (quest_set_slot, "qst_ghost_lady", 2, ":var_1"),
    (quest_set_slot, "qst_ghost_lady", 3, ":var_0"),
    (quest_set_slot, "qst_ghost_lady", 4, ":var_4"),
    (quest_set_slot, "qst_ghost_lady", 15, ":var_5"),
    (quest_set_slot, "qst_ghost_lady", 6, ":var_3"),
    (quest_set_slot, "qst_ghost_lady", 23, 0),
    (quest_set_slot, "qst_ghost_lady", 25, 10000),
    (quest_set_slot, "qst_ghost_lady", 10, 0),
    (quest_set_slot, "qst_ghost_lady", 11, 0),
    (troop_set_slot, ":var_3", slot_troop_cur_center, ":var_2"),
    (setup_quest_text, "qst_ghost_lady"),
    (str_store_troop_name_link, s4, ":var_1"),
    (str_store_party_name_link, s5, ":var_2"),
    (str_store_string, s60, "@A passing messenger told you {s4}'s wife died suddenly in {s5}."),
    (display_message, "@A passing messenger tells you {s4}'s wife died suddenly in {s5}.", 0x66CCFF),
    (add_quest_note_from_sreg, "qst_ghost_lady", 0, 60, 0),
    (start_quest, "qst_ghost_lady"),
    (display_message, "str_quest_log_updated", 0x66CCFF),

]),

(168.070007,
[
    (call_script, "script_auto_repair_buildings"),

]),

(480.200012,
[
    (call_script, "script_random_build_buildings"),

]),

(5.110000,
[
    (store_random_in_range, ":var_0", 0, 250),
    (try_begin),
        (neg|ge, ":var_0", 4),
        (is_currently_night),
        (play_sound, "snd_encounter_pop_sfx_four"),
    (else_try),
        (neg|ge, ":var_0", 8),
        (play_sound, "snd_encounter_pop_sfx_five"),
    (else_try),
        (neg|ge, ":var_0", 12),
        (play_sound, "snd_encounter_pop_sfx_two"),
    (else_try),
        (neg|ge, ":var_0", 16),
        (play_sound, "snd_encounter_pop_sfx_three"),
    (else_try),
        (neg|ge, ":var_0", 20),
        (play_sound, "snd_ambient_thunder"),
    (else_try),
        (neg|ge, ":var_0", 24),
        (play_sound, "snd_ambient_thunderrain"),
    (else_try),
        (neg|ge, ":var_0", 28),
        (play_sound, "snd_ambient_thunderrumble"),
    (else_try),
        (neg|ge, ":var_0", 32),
        (is_currently_night),
        (play_sound, "snd_encounter_pop_sfx_eight"),
    (else_try),
        (neg|ge, ":var_0", 35),
        (is_currently_night),
        (play_sound, "snd_encounter_pop_sfx_six"),
    (else_try),
        (neg|ge, ":var_0", 38),
        (is_currently_night),
        (play_sound, "snd_encounter_pop_sfx_one"),
    (try_end),

]),

(14.000000,
[
    (try_for_parties, ":var_0"),
        (gt, ":var_0", "p_spawn_points_end"),
        (store_faction_of_party, ":var_1", ":var_0"),
        (neg|is_between, ":var_1", "fac_player_supporters_faction", "fac_kingdoms_end"),
        (store_party_size_wo_prisoners, ":var_2", ":var_0"),
        (ge, ":var_2", 150),
        (party_get_battle_opponent, ":var_3", ":var_0"),
        (eq, ":var_3", -1),
        (call_script, "script_party_calculate_strength", ":var_0", 0),
        (assign, ":var_4", reg0),
        (gt, ":var_4", 30000),
        (val_mul, ":var_4", 67),
        (val_div, ":var_4", 100),
        (assign, ":var_5", "p_castle_1"),
        (try_for_range, ":var_6", "p_town_1", ":var_5"),
            (party_slot_eq, ":var_6", slot_center_is_besieged_by, -1),
            (store_faction_of_party, ":var_7", ":var_6"),
            (store_relation, ":var_8", ":var_1", ":var_7"),
            (neg|ge, ":var_8", 0),
            (store_distance_to_party_from_party, ":var_9", ":var_0", ":var_6"),
            (neg|gt, ":var_9", 5),
            (party_collect_attachments_to_party, ":var_6", "p_garrison_plus_lords"),
            (call_script, "script_party_calculate_strength", "p_garrison_plus_lords", 0),
            (assign, ":var_10", reg0),
            (gt, ":var_4", ":var_10"),
            (store_random_in_range, ":var_11", 0, 100),
            (neg|ge, ":var_11", 15),
            (party_set_ai_behavior, ":var_0", 4),
            (party_set_ai_object, ":var_0", ":var_6"),
            (party_set_ai_initiative, ":var_0", 0),
            (party_set_slot, ":var_6", slot_center_is_besieged_by, ":var_0"),
            (call_script, "script_village_set_state", ":var_6", 5),
            (str_store_party_name, s5, ":var_0"),
            (str_store_party_name, s6, ":var_6"),
            (display_message, "@{s5} launches a surprise attack on {s6}!", 0x66CCFF),
            (try_begin),
                (this_or_next|party_slot_eq, ":var_6", slot_town_lord, "trp_player"),
                (eq, ":var_7", "fac_player_supporters_faction"),
                (call_script, "script_add_notification_menu", "mnu_notification_center_under_siege_special", ":var_6", ":var_0"),
            (try_end),
            (assign, ":var_5", 0),
        (try_end),
    (try_end),

]),

(384.000000,
[
    (store_current_day, ":var_0"),
    (gt, ":var_0", 365),
    (store_character_level, ":var_1", "trp_player"),
    (gt, ":var_1", 30),
    (store_random_in_range, ":var_2", 0, 100),
    (neg|ge, ":var_2", 5),
    (assign, ":var_3", 0),
    (try_for_range, ":var_4", "fac_dragon_knights", "fac_player_knights"),
        (faction_get_slot, ":var_5", ":var_4", 68),
        (assign, ":var_6", 0),
        (try_for_range, ":var_7", "p_town_1", "p_village_1"),
            (party_slot_eq, ":var_7", 289, ":var_5"),
            (assign, ":var_6", 1),
        (try_end),
        (eq, ":var_6", 0),
        (val_add, ":var_3", 1),
    (try_end),
    (gt, ":var_3", 0),
    (assign, ":var_8", 0),
    (store_random_in_range, ":var_9", 0, ":var_3"),
    (val_add, ":var_9", 1),
    (try_for_range, ":var_4", "fac_dragon_knights", "fac_player_knights"),
        (eq, ":var_8", 0),
        (faction_get_slot, ":var_5", ":var_4", 68),
        (assign, ":var_6", 0),
        (try_for_range, ":var_7", "p_town_1", "p_village_1"),
            (party_slot_eq, ":var_7", 289, ":var_5"),
            (assign, ":var_6", 1),
        (try_end),
        (eq, ":var_6", 0),
        (val_sub, ":var_9", 1),
        (eq, ":var_9", 0),
        (assign, ":var_8", ":var_4"),
    (try_end),
    (assign, ":var_10", 0),
    (try_for_range, ":var_11", "fac_kingdom_1", "fac_kingdoms_end"),
        (faction_slot_eq, ":var_11", slot_faction_state, 0),
        (faction_get_slot, ":var_12", ":var_11", slot_faction_leader),
        (assign, ":var_6", 0),
        (try_for_range, ":var_7", "p_town_1", "p_village_1"),
            (eq, ":var_6", 0),
            (party_slot_eq, ":var_7", slot_town_lord, ":var_12"),
            (party_slot_eq, ":var_7", 289, 0),
            (party_slot_eq, ":var_7", slot_center_is_besieged_by, -1),
            (assign, ":var_6", 1),
        (try_end),
        (eq, ":var_6", 1),
        (val_add, ":var_10", 1),
    (try_end),
    (gt, ":var_10", 0),
    (assign, ":var_13", 0),
    (assign, ":var_14", 0),
    (store_random_in_range, ":var_15", 0, ":var_10"),
    (val_add, ":var_15", 1),
    (try_for_range, ":var_11", "fac_kingdom_1", "fac_kingdoms_end"),
        (eq, ":var_13", 0),
        (faction_slot_eq, ":var_11", slot_faction_state, 0),
        (faction_get_slot, ":var_12", ":var_11", slot_faction_leader),
        (assign, ":var_6", 0),
        (try_for_range, ":var_7", "p_town_1", "p_village_1"),
            (eq, ":var_6", 0),
            (party_slot_eq, ":var_7", slot_town_lord, ":var_12"),
            (party_slot_eq, ":var_7", 289, 0),
            (party_slot_eq, ":var_7", slot_center_is_besieged_by, -1),
            (assign, ":var_6", 1),
            (val_sub, ":var_15", 1),
            (eq, ":var_15", 0),
            (assign, ":var_13", ":var_12"),
            (assign, ":var_14", ":var_7"),
        (try_end),
    (try_end),
    (faction_get_slot, ":var_16", ":var_8", 68),
    (party_set_slot, ":var_14", 289, ":var_16"),
    (call_script, "script_add_notification_menu", "mnu_notification_order_founded", ":var_8", ":var_14"),

]),

(312.000000,
[
    (store_random_in_range, ":var_0", 0, 100),
    (neg|ge, ":var_0", 5),
    (assign, ":var_1", 0),
    (try_for_range, ":var_2", "p_castle_1", "p_village_1"),
        (party_slot_eq, ":var_2", 289, 0),
        (party_slot_eq, ":var_2", slot_center_is_besieged_by, -1),
        (party_get_slot, ":var_3", ":var_2", slot_town_lord),
        (is_between, ":var_3", "trp_npc_adonja", "trp_knight_1_1_wife"),
        (neg|is_between, ":var_3", "trp_kingdom_1_lord", "trp_knight_1_1"),
        (neg|is_between, ":var_3", "trp_kingdom_1_pretender", "trp_knight_1_1_wife"),
        (val_add, ":var_1", 1),
    (try_end),
    (gt, ":var_1", 0),
    (assign, ":var_4", 0),
    (store_random_in_range, ":var_5", 0, ":var_1"),
    (val_add, ":var_5", 1),
    (try_for_range, ":var_2", "p_castle_1", "p_village_1"),
        (eq, ":var_4", 0),
        (party_slot_eq, ":var_2", 289, 0),
        (party_slot_eq, ":var_2", slot_center_is_besieged_by, -1),
        (party_get_slot, ":var_3", ":var_2", slot_town_lord),
        (is_between, ":var_3", "trp_npc_adonja", "trp_knight_1_1_wife"),
        (neg|is_between, ":var_3", "trp_kingdom_1_lord", "trp_knight_1_1"),
        (neg|is_between, ":var_3", "trp_kingdom_1_pretender", "trp_knight_1_1_wife"),
        (val_sub, ":var_5", 1),
        (eq, ":var_5", 0),
        (assign, ":var_4", ":var_2"),
    (try_end),
    (call_script, "script_generate_minor_order", ":var_4"),
    (assign, ":var_6", reg0),
    (neg|eq, ":var_6", -1),
    (faction_get_slot, ":var_7", ":var_6", 68),
    (party_set_slot, ":var_4", 289, ":var_7"),
    (party_get_slot, ":var_8", ":var_4", slot_town_lord),
    (try_begin),
        (troop_slot_eq, ":var_8", 158, 0),
        (troop_set_slot, ":var_8", 158, ":var_7"),
        (troop_set_slot, ":var_8", 159, 2),
        (troop_set_slot, ":var_8", 160, 4),
    (try_end),
    (call_script, "script_add_notification_menu", "mnu_notification_order_founded", ":var_6", ":var_4"),

]),

(9.000000,
[
    (try_for_range, ":var_0", "fac_player_supporters_faction", "fac_kingdoms_end"),
        (faction_slot_eq, ":var_0", slot_faction_state, 0),
        (assign, ":var_1", 0),
        (assign, ":var_2", 0),
        (try_begin),
            (eq, ":var_0", "fac_kingdom_1"),
            (assign, ":var_1", "fac_lion_knights"),
            (assign, ":var_2", "p_town_6"),
        (else_try),
            (eq, ":var_0", "fac_kingdom_2"),
            (assign, ":var_1", "fac_dragon_knights"),
            (assign, ":var_2", "p_town_13"),
        (else_try),
            (eq, ":var_0", "fac_kingdom_3"),
            (assign, ":var_1", "fac_windriders_knights"),
            (assign, ":var_2", "p_town_10"),
        (else_try),
            (eq, ":var_0", "fac_kingdom_4"),
            (assign, ":var_1", "fac_valkyrie_knights"),
            (assign, ":var_2", "p_town_1"),
        (else_try),
            (eq, ":var_0", "fac_kingdom_5"),
            (assign, ":var_1", "fac_immortal_knights"),
            (assign, ":var_2", "p_town_5"),
        (else_try),
            (assign, ":var_1", "fac_player_knights"),
            (assign, ":var_2", "p_town_1"),
        (try_end),
        (faction_get_slot, ":var_3", ":var_1", 68),
        (faction_get_slot, ":var_4", ":var_1", 69),
        (try_begin),
            (party_slot_eq, ":var_2", 289, ":var_3"),
            (store_faction_of_party, ":var_5", ":var_2"),
            (eq, ":var_5", ":var_0"),
        (else_try),
            (assign, ":var_2", 0),
            (try_for_range, ":var_6", "p_town_1", "p_village_1"),
                (eq, ":var_2", 0),
                (party_slot_eq, ":var_6", 289, ":var_3"),
                (store_faction_of_party, ":var_7", ":var_6"),
                (eq, ":var_7", ":var_0"),
                (assign, ":var_2", ":var_6"),
            (try_end),
        (try_end),
        (neg|eq, ":var_2", 0),
        (faction_get_slot, ":var_8", ":var_0", 73),
        (faction_get_slot, ":var_9", ":var_0", 74),
        (try_begin),
            (gt, ":var_8", 0),
            (neg|party_is_active, ":var_8"),
            (assign, ":var_8", 0),
            (faction_set_slot, ":var_0", 73, 0),
        (try_end),
        (assign, ":var_10", -1),
        (try_begin),
            (call_script, "script_cf_faction_get_random_enemy_faction", ":var_0"),
            (assign, ":var_10", reg0),
        (try_end),
        (store_current_day, ":var_11"),
        (try_begin),
            (neg|eq, ":var_10", -1),
            (eq, ":var_8", 0),
            (store_sub, ":var_12", ":var_11", ":var_9"),
            (ge, ":var_12", 30),
            (store_random_in_range, ":var_13", 0, 100),
            (neg|ge, ":var_13", 1),
            (faction_set_slot, ":var_0", 74, ":var_11"),
            (assign, ":var_9", ":var_11"),
            (spawn_around_party, ":var_2", "pt_errant_knights"),
            (assign, ":var_8", reg0),
            (faction_set_slot, ":var_0", 73, ":var_8"),
            (party_set_slot, ":var_8", slot_party_home_center, ":var_2"),
            (party_set_flags, ":var_8", 65536, 0),
            (party_set_faction, ":var_8", ":var_0"),
            (str_store_faction_name, s5, ":var_1"),
            (party_set_name, ":var_8", "@{s5} War Party"),
            (party_set_ai_initiative, ":var_8", 100),
            (party_set_aggressiveness, ":var_8", 10),
            (party_set_courage, ":var_8", 10),
            (party_set_helpfulness, ":var_8", 200),
            (party_set_slot, ":var_8", slot_party_ai_state, -1),
            (party_set_slot, ":var_8", slot_party_type, 19),
            (store_character_level, ":var_14", "trp_player"),
            (val_clamp, ":var_14", 10, 41),
            (store_mul, ":var_15", ":var_14", 12),
            (val_div, ":var_15", 10),
            (store_mul, ":var_16", ":var_14", 24),
            (val_div, ":var_16", 10),
            (store_random_in_range, ":var_17", ":var_15", ":var_16"),
            (party_add_members, ":var_8", ":var_3", ":var_17"),
            (store_mul, ":var_18", ":var_14", 20),
            (val_div, ":var_18", 10),
            (store_mul, ":var_19", ":var_14", 40),
            (val_div, ":var_19", 10),
            (store_random_in_range, ":var_20", ":var_18", ":var_19"),
            (party_add_members, ":var_8", ":var_4", ":var_20"),
            (call_script, "script_party_calculate_strength", ":var_8", 0),
            (party_set_slot, ":var_8", slot_town_wealth, reg0),
            (str_store_faction_name, s11, ":var_0"),
            (str_store_faction_name, s12, ":var_1"),
            (str_store_party_name, s13, ":var_2"),
            (display_message, "@The {s12} from {s13} have assembled a war party to assist the {s11}."),
        (try_end),
        (neg|eq, ":var_8", 0),
        (party_get_slot, ":var_21", ":var_8", slot_party_ai_state),
        (try_begin),
            (neg|eq, ":var_21", 14),
            (store_sub, ":var_12", ":var_11", ":var_9"),
            (party_get_slot, ":var_22", ":var_8", slot_town_wealth),
            (val_div, ":var_22", 5),
            (call_script, "script_party_calculate_strength", ":var_8", 0),
            (this_or_next|ge, ":var_22", reg0),
            (this_or_next|ge, ":var_12", 15),
            (eq, ":var_10", -1),
            (party_set_ai_behavior, ":var_8", 1),
            (party_set_ai_object, ":var_8", ":var_2"),
            (party_set_slot, ":var_8", slot_party_home_center, ":var_2"),
            (party_set_slot, ":var_8", slot_party_ai_state, 14),
            (assign, ":var_21", 14),
        (try_end),
        (neg|eq, ":var_21", 14),
        (faction_get_slot, ":var_23", ":var_0", slot_faction_marshall),
        (try_begin),
            (store_random_in_range, ":var_24", 0, 100),
            (this_or_next|neg|ge, ":var_24", 20),
            (neg|eq, ":var_21", 4),
            (ge, ":var_23", 0),
            (troop_get_slot, ":var_25", ":var_23", slot_troop_leaded_party),
            (party_is_active, ":var_25"),
            (this_or_next|eq, ":var_23", "trp_player"),
            (this_or_next|party_slot_eq, ":var_25", slot_party_ai_state, 1),
            (party_slot_eq, ":var_25", slot_party_ai_state, 10),
            (party_set_ai_behavior, ":var_8", 10),
            (party_set_ai_object, ":var_8", ":var_25"),
            (party_set_slot, ":var_8", slot_party_ai_state, 11),
            (assign, ":var_21", 11),
        (else_try),
            (store_random_in_range, ":var_24", 0, 100),
            (this_or_next|neg|ge, ":var_24", 50),
            (neg|eq, ":var_21", 4),
            (assign, ":var_26", 0),
            (try_for_range, ":var_27", "p_village_1", "p_salt_mine"),
                (eq, ":var_26", 0),
                (party_slot_eq, ":var_27", slot_village_state, 1),
                (store_faction_of_party, ":var_28", ":var_27"),
                (eq, ":var_28", ":var_0"),
                (assign, ":var_26", ":var_27"),
            (try_end),
            (try_begin),
                (eq, ":var_26", 0),
                (try_for_range, ":var_29", "p_town_1", "p_village_1"),
                    (eq, ":var_26", 0),
                    (party_slot_ge, ":var_29", slot_center_is_besieged_by, 1),
                    (store_faction_of_party, ":var_28", ":var_29"),
                    (eq, ":var_28", ":var_0"),
                    (assign, ":var_26", ":var_29"),
                (try_end),
            (try_end),
            (try_begin),
                (eq, ":var_26", 0),
                (call_script, "script_get_closest_walled_center_of_faction", ":var_8", ":var_10"),
                (neg|eq, reg0, -1),
                (call_script, "script_get_closest_center_of_faction", reg0, ":var_0"),
                (neg|eq, reg0, -1),
                (assign, ":var_26", reg0),
            (try_end),
            (gt, ":var_26", 0),
            (party_set_ai_behavior, ":var_8", 3),
            (party_set_ai_object, ":var_8", ":var_26"),
            (party_set_ai_patrol_radius, ":var_8", 1),
            (party_set_slot, ":var_8", slot_party_ai_state, 4),
            (assign, ":var_21", 4),
        (try_end),
    (try_end),

]),

(24.000000,
[
    (assign, ":var_0", "fac_kingdoms_end"),
    (try_for_range, ":var_1", "fac_kingdom_1", ":var_0"),
        (neg|faction_slot_eq, ":var_1", slot_faction_state, 0),
        (assign, ":var_2", -1),
        (assign, ":var_3", 0),
        (try_for_range, ":var_4", "fac_kingdom_1", "fac_kingdoms_end"),
            (neg|eq, ":var_4", ":var_1"),
            (faction_slot_eq, ":var_4", slot_faction_state, 0),
            (assign, ":var_5", 0),
            (try_for_range, ":var_6", "trp_kingdom_1_lord", "trp_knight_1_1_wife"),
                (neg|troop_slot_ge, ":var_6", slot_troop_prisoner_of_party, 0),
                (troop_get_slot, ":var_7", ":var_6", slot_troop_original_faction),
                (eq, ":var_7", ":var_1"),
                (store_troop_faction, ":var_8", ":var_6"),
                (this_or_next|eq, ":var_8", ":var_4"),
                (eq, ":var_8", "fac_outlaws"),
                (val_add, ":var_5", 1),
            (try_end),
            (assign, ":var_9", 0),
            (try_for_range, ":var_10", "p_town_1", "p_village_1"),
                (party_get_slot, ":var_11", ":var_10", slot_town_lord),
                (ge, ":var_11", 1),
                (neg|troop_slot_ge, ":var_11", slot_troop_prisoner_of_party, 0),
                (store_troop_faction, ":var_8", ":var_11"),
                (eq, ":var_8", ":var_4"),
                (troop_get_slot, ":var_7", ":var_11", slot_troop_original_faction),
                (eq, ":var_7", ":var_1"),
                (val_add, ":var_9", 2),
                (try_begin),
                    (party_slot_eq, ":var_10", slot_party_type, 3),
                    (val_add, ":var_9", 2),
                (try_end),
            (try_end),
            (try_begin),
                (ge, ":var_9", 6),
                (gt, ":var_5", ":var_3"),
                (assign, ":var_3", ":var_5"),
                (assign, ":var_2", ":var_4"),
            (try_end),
        (try_end),
        (try_begin),
            (neg|ge, ":var_3", 5),
            (assign, ":var_2", -1),
        (try_end),
        (gt, ":var_2", -1),
        (assign, ":var_0", 0),
        (faction_get_slot, ":var_12", ":var_1", slot_faction_leader),
        (store_troop_faction, ":var_13", ":var_12"),
        (try_begin),
            (this_or_next|eq, ":var_13", "fac_player_faction"),
            (eq, ":var_13", "fac_player_supporters_faction"),
            (assign, ":var_12", -1),
            (try_for_range, ":var_14", "trp_kingdom_1_pretender", "trp_knight_1_1_wife"),
                (neg|troop_slot_ge, ":var_14", slot_troop_prisoner_of_party, 0),
                (troop_get_slot, ":var_15", ":var_14", slot_troop_original_faction),
                (eq, ":var_15", ":var_1"),
                (store_troop_faction, ":var_8", ":var_14"),
                (neg|eq, ":var_8", "fac_player_faction"),
                (neg|eq, ":var_8", "fac_player_supporters_faction"),
                (assign, ":var_12", ":var_14"),
            (try_end),
            (try_begin),
                (neg|ge, ":var_12", 0),
                (assign, ":var_12", ":var_6"),
            (try_end),
        (try_end),
        (faction_set_slot, ":var_1", slot_faction_leader, ":var_12"),
        (call_script, "script_change_troop_faction", ":var_12", ":var_1"),
        (troop_set_slot, ":var_12", slot_troop_occupation, 2),
        (call_script, "script_add_notification_menu", "mnu_notification_kingdom_restoration", ":var_1", ":var_2"),
    (try_end),

]),

(24.000000,
[
    (try_for_range, ":var_0", "trp_npc_adonja", "trp_knight_1_1_wife"),
        (troop_slot_eq, ":var_0", slot_troop_occupation, 2),
        (troop_get_slot, ":var_1", ":var_0", slot_troop_leaded_party),
        (ge, ":var_1", 1),
        (party_is_active, ":var_1"),
        (assign, ":var_2", 10),
        (assign, ":var_3", ":var_2"),
        (party_get_num_prisoner_stacks, ":var_4", ":var_1"),
        (assign, ":var_5", ":var_4"),
        (try_for_range_backwards, ":var_6", 0, ":var_5"),
            (gt, ":var_3", 0),
            (party_prisoner_stack_get_troop_id, ":var_7", ":var_1", ":var_6"),
            (gt, ":var_7", -1),
            (neg|troop_is_hero, ":var_7"),
            (party_count_prisoners_of_type, ":var_8", ":var_1", ":var_7"),
            (val_min, ":var_8", ":var_3"),
            (val_sub, ":var_3", ":var_8"),
            (store_troop_faction, ":var_9", ":var_7"),
            (troop_get_slot, ":var_10", ":var_0", slot_troop_original_faction),
            (try_begin),
                (eq, ":var_9", "fac_culture_1"),
                (assign, ":var_9", "fac_kingdom_1"),
            (else_try),
                (eq, ":var_9", "fac_culture_2"),
                (assign, ":var_9", "fac_kingdom_2"),
            (else_try),
                (eq, ":var_9", "fac_culture_3"),
                (assign, ":var_9", "fac_kingdom_3"),
            (else_try),
                (eq, ":var_9", "fac_culture_4"),
                (assign, ":var_9", "fac_kingdom_4"),
            (else_try),
                (eq, ":var_9", "fac_culture_5"),
                (assign, ":var_9", "fac_kingdom_5"),
            (else_try),
                (eq, ":var_9", "fac_culture_6"),
                (assign, ":var_9", "fac_player_supporters_faction"),
            (else_try),
                (eq, ":var_9", "fac_lion_knights"),
                (assign, ":var_9", "fac_kingdom_1"),
            (else_try),
                (eq, ":var_9", "fac_dragon_knights"),
                (assign, ":var_9", "fac_kingdom_2"),
            (else_try),
                (eq, ":var_9", "fac_windriders_knights"),
                (assign, ":var_9", "fac_kingdom_3"),
            (else_try),
                (eq, ":var_9", "fac_valkyrie_knights"),
                (assign, ":var_9", "fac_kingdom_4"),
            (else_try),
                (this_or_next|eq, ":var_9", "fac_immortal_knights"),
                (eq, ":var_9", "fac_shadow_knights"),
                (assign, ":var_9", "fac_kingdom_5"),
            (else_try),
                (this_or_next|eq, ":var_9", "fac_griffon_knights"),
                (this_or_next|eq, ":var_9", "fac_player_knights"),
                (eq, ":var_9", "fac_silvermist_knights"),
                (assign, ":var_9", "fac_player_supporters_faction"),
            (try_end),
            (try_begin),
                (eq, ":var_9", ":var_10"),
                (party_remove_prisoners, ":var_1", ":var_7", ":var_8"),
                (party_add_members, ":var_1", ":var_7", ":var_8"),
            (else_try),
            (try_end),
            (try_begin),
                (eq, ":var_3", 0),
                (assign, ":var_5", 0),
            (try_end),
        (try_end),
    (try_end),
    (try_for_parties, ":var_1"),
        (try_begin),
            (is_between, ":var_1", "p_town_1", "p_village_1"),
            (assign, ":var_11", ":var_1"),
            (party_get_slot, ":var_12", ":var_11", slot_town_lord),
            (gt, ":var_12", 0),
            (neg|eq, ":var_12", "trp_player"),
            (assign, ":var_2", 5),
            (assign, ":var_13", 0),
            (try_begin),
                (party_slot_eq, ":var_11", slot_party_type, 3),
                (party_get_slot, ":var_13", ":var_11", slot_center_ransom_broker),
                (gt, ":var_13", 0),
                (assign, ":var_2", 30),
            (try_end),
            (party_get_num_prisoners, ":var_14", ":var_1"),
            (gt, ":var_14", 50),
            (assign, ":var_3", ":var_2"),
            (party_get_num_prisoner_stacks, ":var_4", ":var_11"),
            (assign, ":var_5", ":var_4"),
            (try_for_range_backwards, ":var_6", 0, ":var_5"),
                (gt, ":var_3", 0),
                (party_prisoner_stack_get_troop_id, ":var_7", ":var_11", ":var_6"),
                (gt, ":var_7", -1),
                (neg|troop_is_hero, ":var_7"),
                (party_count_prisoners_of_type, ":var_8", ":var_11", ":var_7"),
                (val_min, ":var_8", ":var_3"),
                (val_sub, ":var_3", ":var_8"),
                (call_script, "script_game_get_prisoner_price", ":var_7"),
                (assign, ":var_15", reg0),
                (val_mul, ":var_15", ":var_8"),
                (val_div, ":var_15", 2),
                (party_remove_prisoners, ":var_11", ":var_7", ":var_8"),
                (store_div, ":var_16", ":var_15", 1000),
                (val_max, ":var_16", 1),
                (call_script, "script_change_center_prosperity", ":var_11", ":var_16"),
                (troop_get_slot, ":var_17", ":var_12", slot_troop_wealth),
                (val_add, ":var_17", ":var_15"),
                (troop_set_slot, ":var_12", slot_troop_wealth, ":var_17"),
                (try_begin),
                    (eq, ":var_3", 0),
                    (assign, ":var_5", 0),
                (try_end),
            (try_end),
        (else_try),
            (party_is_active, ":var_1"),
            (party_stack_get_troop_id, ":var_18", ":var_1", 0),
            (gt, ":var_18", 0),
            (neg|eq, ":var_18", "trp_player"),
            (neg|is_between, ":var_18", "trp_npc_adonja", "trp_knight_1_1_wife"),
            (party_get_num_companions, ":var_19", ":var_1"),
            (party_get_num_prisoners, ":var_20", ":var_1"),
            (val_mul, ":var_19", 3),
            (val_div, ":var_19", 2),
            (gt, ":var_20", ":var_19"),
            (party_get_num_prisoner_stacks, ":var_4", ":var_1"),
            (assign, ":var_5", ":var_4"),
            (try_for_range_backwards, ":var_6", 0, ":var_5"),
                (party_prisoner_stack_get_troop_id, ":var_7", ":var_1", ":var_6"),
                (party_prisoner_stack_get_size, ":var_8", ":var_1", ":var_6"),
                (party_remove_prisoners, ":var_1", ":var_7", ":var_8"),
                (val_sub, ":var_20", ":var_8"),
                (try_begin),
                    (neg|gt, ":var_19", ":var_20"),
                    (assign, ":var_5", 0),
                (try_end),
            (try_end),
        (try_end),
    (try_end),

]),

(6.000000,
[
    (try_for_parties, ":var_0"),
        (is_between, ":var_0", "p_town_1", "p_village_1"),
        (assign, ":var_1", ":var_0"),
        (party_get_slot, ":var_2", ":var_1", slot_town_lord),
        (gt, ":var_2", 0),
        (neg|eq, ":var_2", "trp_player"),
        (troop_get_slot, ":var_3", ":var_2", slot_troop_leaded_party),
        (gt, ":var_3", 0),
        (party_get_attached_to, ":var_4", ":var_3"),
        (eq, ":var_4", ":var_1"),
        (party_get_slot, ":var_5", ":var_1", 289),
        (gt, ":var_5", 0),
        (call_script, "script_party_get_ideal_size", ":var_3"),
        (assign, ":var_6", reg0),
        (party_get_num_companions, ":var_7", ":var_3"),
        (store_sub, ":var_8", ":var_6", ":var_7"),
        (try_begin),
            (party_count_companions_of_type, ":var_9", ":var_1", ":var_5"),
            (ge, ":var_9", 20),
            (val_sub, ":var_9", 5),
            (gt, ":var_9", 0),
            (val_min, ":var_9", 20),
            (try_begin),
                (gt, ":var_8", 0),
                (val_min, ":var_9", ":var_8"),
                (party_add_members, ":var_3", ":var_5", ":var_9"),
                (party_remove_members, ":var_1", ":var_5", ":var_9"),
                (str_store_troop_name, s1, ":var_2"),
                (assign, reg1, ":var_9"),
                (str_store_troop_name, s2, ":var_5", ":var_9"),
                (str_store_party_name, s3, ":var_1"),
                (display_message, "str_s1_transferred_reg1_s2_from_s3"),
            (else_try),
                (neg|gt, ":var_8", 0),
                (ge, ":var_8", -20),
                (assign, ":var_10", 100),
                (assign, ":var_11", -1),
                (party_get_num_companion_stacks, ":var_12", ":var_3"),
                (try_for_range_backwards, ":var_13", 0, ":var_12"),
                    (party_stack_get_troop_id, ":var_14", ":var_3", ":var_13"),
                    (store_character_level, ":var_15", ":var_14"),
                    (neg|ge, ":var_15", ":var_10"),
                    (assign, ":var_10", ":var_15"),
                    (assign, ":var_11", ":var_14"),
                (try_end),
                (ge, ":var_11", 0),
                (neg|ge, ":var_10", 40),
                (party_count_companions_of_type, ":var_16", ":var_3", ":var_11"),
                (val_min, ":var_9", ":var_16"),
                (party_add_members, ":var_3", ":var_5", ":var_9"),
                (party_remove_members, ":var_3", ":var_11", ":var_9"),
                (party_add_members, ":var_1", ":var_11", ":var_9"),
                (party_remove_members, ":var_1", ":var_5", ":var_9"),
                (str_store_troop_name, s1, ":var_2"),
                (assign, reg1, ":var_9"),
                (str_store_troop_name, s2, ":var_5"),
                (str_store_party_name, s3, ":var_1"),
                (display_message, "str_s1_transferred_reg1_s2_from_s3"),
            (try_end),
        (try_end),
        (try_begin),
            (store_troop_faction, ":var_17", ":var_5"),
            (gt, ":var_17", 0),
            (faction_get_slot, ":var_18", ":var_17", 69),
            (gt, ":var_18", 0),
            (party_count_companions_of_type, ":var_19", ":var_1", ":var_18"),
            (gt, ":var_19", 30),
            (val_sub, ":var_19", 15),
            (gt, ":var_19", 0),
            (val_min, ":var_19", 30),
            (try_begin),
                (gt, ":var_8", 0),
                (val_min, ":var_19", ":var_8"),
                (party_add_members, ":var_3", ":var_18", ":var_19"),
                (party_remove_members, ":var_1", ":var_18", ":var_19"),
                (str_store_troop_name, s1, ":var_2"),
                (assign, reg1, ":var_19"),
                (str_store_troop_name, s2, ":var_18"),
                (str_store_party_name, s3, ":var_1"),
                (display_message, "str_s1_transferred_reg1_s2_from_s3"),
            (else_try),
                (neg|gt, ":var_8", 0),
                (ge, ":var_8", -20),
                (assign, ":var_10", 100),
                (assign, ":var_11", -1),
                (party_get_num_companion_stacks, ":var_12", ":var_3"),
                (try_for_range_backwards, ":var_13", 0, ":var_12"),
                    (party_stack_get_troop_id, ":var_14", ":var_3", ":var_13"),
                    (store_character_level, ":var_15", ":var_14"),
                    (neg|ge, ":var_15", ":var_10"),
                    (assign, ":var_10", ":var_15"),
                    (assign, ":var_11", ":var_14"),
                (try_end),
                (ge, ":var_11", 0),
                (neg|ge, ":var_10", 40),
                (party_count_companions_of_type, ":var_16", ":var_3", ":var_11"),
                (val_min, ":var_19", ":var_16"),
                (party_add_members, ":var_3", ":var_18", ":var_19"),
                (party_remove_members, ":var_3", ":var_11", ":var_19"),
                (party_add_members, ":var_1", ":var_11", ":var_19"),
                (party_remove_members, ":var_1", ":var_18", ":var_19"),
                (str_store_troop_name, s1, ":var_2"),
                (assign, reg1, ":var_19"),
                (str_store_troop_name, s2, ":var_18"),
                (str_store_party_name, s3, ":var_1"),
                (display_message, "str_s1_transferred_reg1_s2_from_s3"),
            (try_end),
        (try_end),
    (try_end),

]),

(24.000000,
[
    (troop_get_slot, ":var_0", "trp_loot_pool", 188),
    (troop_get_slot, ":var_1", "trp_loot_pool", 189),
    (gt, ":var_1", 0),
    (neg|ge, ":var_0", ":var_1"),
    (val_add, ":var_0", 1),
    (troop_set_slot, "trp_loot_pool", 188, ":var_0"),
    (ge, ":var_0", ":var_1"),
    (display_message, "str_your_carriage_has_been_finished"),
    (play_sound, "snd_bellchant"),

]),

(12.000000,
[
    (troop_get_slot, ":var_0", "trp_player", slot_troop_renown),
    (store_div, ":var_1", ":var_0", 400),
    (gt, ":var_1", "$g_hp_bar_enemy"),
    (val_sub, ":var_1", "$g_hp_bar_enemy"),
    (val_add, "$g_hp_bar_enemy", ":var_1"),
    (set_show_messages, 0),
    (try_for_range, ":var_2", "trp_npc_adonja", "trp_knight_1_1_wife"),
        (troop_is_hero, ":var_2"),
        (troop_slot_eq, ":var_2", slot_lord_reputation_type, 1),
        (call_script, "script_troop_change_relation_with_troop", "trp_player", ":var_2", ":var_1"),
    (try_end),
    (set_show_messages, 1),

]),

(24.000000,
[
    (try_for_parties, ":var_0"),
        (party_get_template_id, ":var_1", ":var_0"),
        (this_or_next|is_between, ":var_1", "pt_wolfbode", "pt_refugees"),
        (this_or_next|eq, ":var_1", "pt_sea_raider_army"),
        (this_or_next|eq, ":var_1", "pt_heretics_army"),
        (this_or_next|eq, ":var_1", "pt_snake_cult_army"),
        (this_or_next|eq, ":var_1", "pt_mystmountain_army"),
        (this_or_next|eq, ":var_1", "pt_jatu_army"),
        (eq, ":var_1", "pt_peasant_army"),
        (party_set_flags, ":var_0", 16384, 1),
    (try_end),

]),


]